Beispiel #1
0
  @Override
  public boolean onKeyDown(int keyCode, KeyEvent event) {
    // TODO Auto-generated method stub
    if (keyCode == KeyEvent.KEYCODE_BACK || keyCode == KeyEvent.KEYCODE_HOME) {

      // 如果此时侧栏展开,则让其收起
      if (slidingMenu.isActivated()) {
        slidingMenu.toggle();
        // 返回true让程序不退出
        return true;
      }

      // 如果是编辑模式则退出编辑模式
      if (editmodel) {
        toNormal();
        return true;
      }

      if ((System.currentTimeMillis() - exitTime) > 2000) {
        Toast.makeText(MainActivity.this, "再按一次退出程序", Toast.LENGTH_SHORT).show();
        exitTime = System.currentTimeMillis();
      } else {
        MainActivity.this.finish();
        System.exit(0);
      }
      return true;
    }
    return super.onKeyDown(keyCode, event);
  }
  @Override
  public boolean onOptionsItemSelected(MenuItem item) {
    boolean isValid = false;
    switch (item.getItemId()) {
      case R.id.savetaskMI:
        isValid = editATaskAction();
        if (isValid == true) finish();
        break;

      case R.id.addtaskMI:
        isValid = createATaskAction();
        if (isValid == true) {
          initilizeVariables();
          initilizeForNewTask();
          titleInputext.setText("");
          descriptionInputText.setText("");

          if (drawer.isMenuShowing()) drawer.toggle();

          toastWithGravity("Task Added!");
        }
        EasyTracker.getTracker()
            .sendEvent("UI-ActionBar", "Add Task-Append", "ActionBar", (long) 0);
        break;

      case R.id.proximityMI:
        AlertDialog diaBox = locationEditText();
        diaBox.show();
        EasyTracker.getTracker().sendEvent("UI-ActionBar", "Add Proximity", "ActionBar", (long) 0);
        break;

      case R.id.alarmMI:
        drawer.toggle(false);
        EasyTracker.getTracker()
            .sendEvent("UI-ActionBar", "Toggle Alarm Menu", "ActionBar", (long) 0);
        break;

      case R.id.backMI:
        EasyTracker.getTracker().sendEvent("UI-ActionBar", "back To Main", "ActionBar", (long) 0);
        finish();
        break;
    }

    return super.onOptionsItemSelected(item);
  }
 /**
  * public boolean onCreateOptionsMenu(android.view.Menu menu) { super.onCreateOptionsMenu(menu);
  * MenuInflater inflater = getMenuInflater(); inflater.inflate(R.menu.sidemapmenu, menu); return
  * true; } *
  */
 @Override
 public boolean onOptionsItemSelected(MenuItem item) {
   switch (item.getItemId()) {
     case android.R.id.home:
       sm.toggle();
       return true;
   }
   return super.onOptionsItemSelected(item);
 }
  @Override
  public boolean onKeyDown(int keycode, KeyEvent e) {
    switch (keycode) {
      case KeyEvent.KEYCODE_MENU:
        drawer.toggle(false);
        return true;
    }

    return super.onKeyDown(keycode, e);
  }
  @Override
  public boolean onOptionsItemSelected(MenuItem item) {
    switch (item.getItemId()) {
      case android.R.id.home:
        {
          slidingMenu.toggle(true);
        }
    }

    return super.onOptionsItemSelected(item);
  }
  protected void onCreate(Bundle savedInstanceState, int resLayout) {
    super.onCreate(savedInstanceState);
    supportsSDK = android.os.Build.VERSION.SDK_INT < android.os.Build.VERSION_CODES.HONEYCOMB;
    this.resLayout = resLayout;
    app = (TwitterListApplication) getApplication();
    setUpViews();
    getAPI();
    onCreate();

    if (requiresInternet) {
      if (app.getUserProfile() != null && !app.getAccessToken().equals("0")) {
        setUserUIControlsLoggedIn(app.getUserProfile());
        onGettingUserInfo(app.getUserProfile());
      } else if (!app.getAccessToken().equals("0")) {
        getUserInfo();
      } else {
        if (!app.isStarted()) {
          menu.toggle();
        }
        showErrorMessage();
      }
    }
    app.setStarted(true);
  }
 private void showUserProfile() {
   menu.toggle();
   Intent I = new Intent(this, UserProfileActivity.class);
   startActivity(I);
   finish();
 }
 @OptionsItem
 void homeSelected() {
   sm.toggle();
 }
Beispiel #9
0
 /** Toggle the SlidingMenu. If it is open, it will be closed, and vice versa. */
 public void toggle() {
   toggle(true);
 }
Beispiel #10
0
  @Override
  public void onClick(View v) {
    // TODO Auto-generated method stub
    switch (v.getId()) {
      case R.id.previous:
        if (month.get(Calendar.MONTH) == month.getActualMinimum(Calendar.MONTH)) {
          month.set((month.get(Calendar.YEAR) - 1), month.getActualMaximum(Calendar.MONTH), 1);
        } else {
          month.set(Calendar.MONTH, month.get(Calendar.MONTH) - 1);
        }
        refreshCalendar();
        break;

      case R.id.wall:
        if (menu != null) {
          menu.toggle();
        }

        Intent i = new Intent(Calender.this, Home.class);
        Calender.this.finish();
        startActivity(i);
        break;

      case R.id.servicelist:
        if (menu != null) {
          menu.toggle();
        }

        Intent service = new Intent(Calender.this, Servicelist.class);
        Calender.this.finish();
        startActivity(service);
        break;

      case R.id.next:
        if (month.get(Calendar.MONTH) == month.getActualMaximum(Calendar.MONTH)) {
          month.set((month.get(Calendar.YEAR) + 1), month.getActualMinimum(Calendar.MONTH), 1);
        } else {
          month.set(Calendar.MONTH, month.get(Calendar.MONTH) + 1);
        }
        refreshCalendar();
        break;

      case R.id.backButton:
        break;

      case R.id.rightButton:
        if (menu1 == null) {
          System.out.println("inside view null");
          view1 = Calender.this.getLayoutInflater().inflate(R.layout.addanappointment, null);
          menu1 = new SlidingMenu(this);
          menu1.setMode(SlidingMenu.RIGHT);
          menu1.setTouchModeAbove(SlidingMenu.TOUCHMODE_NONE);
          menu1.setBehindOffsetRes(R.dimen.sliding_limit);
          menu1.setMenu(view1);
          menu1.attachToActivity(this, SlidingMenu.SLIDING_CONTENT);
          menu1.toggle();
          intiliazeright(view1);
        } else {

          System.out.println("inside view not null");
          menu1.toggle();
          try {
            fname.setText("");
          } catch (Exception e) {
            // TODO Auto-generated catch block
            e.printStackTrace();
          }
          try {
            lname.setText("");
          } catch (Exception e) {
            // TODO Auto-generated catch block
            e.printStackTrace();
          }
          try {
            adult_counter.setText("1");
            child_counter.setText("0");
          } catch (Exception e) {
            // TODO Auto-generated catch block
            e.printStackTrace();
          }
        }
        break;

      case R.id.scheduletime:
        Calendar calender = Calendar.getInstance();
        DatePickerDialog datePicker =
            new DatePickerDialog(
                Calender.this,
                new MyDateListener(),
                calender.get(Calendar.YEAR),
                calender.get(Calendar.MONTH),
                calender.get(Calendar.DAY_OF_MONTH));

        datePicker.show();
        break;

      case R.id.adult_plus:
        counter_adult = counter_adult + 1;
        Log.e("add counter", Integer.toString(counter_adult));
        adult_counter.setText(Integer.toString(counter_adult));

        break;
      case R.id.adult_minus:
        if (counter_adult == 0) {
          // adult_counter.setText(Integer.toString(counter_adult));
        } else {
          counter_adult = counter_adult - 1;
          Log.e("add counter", Integer.toString(counter_adult));
          adult_counter.setText(Integer.toString(counter_adult));
        }
        break;

      case R.id.child_plus:
        counter_child = counter_child + 1;
        child_counter.setText(Integer.toString(counter_child));
        break;

      case R.id.child_minus:
        if (counter_child == 0) {

        } else {
          counter_child = counter_child - 1;
          child_counter.setText(Integer.toString(counter_child));
        }
        break;

      case R.id.edit_save:
        if (menu1 != null) {
          menu1.toggle();
        }
        break;

      default:
        break;
    }
  }
 @Override
 public void onBackPressed() {
   if (slidingMenu.isMenuShowing()) slidingMenu.toggle(true);
   else super.onBackPressed();
 }
 /** Toggle the SlidingMenu. If it is open, it will be closed, and vice versa. */
 public void toggle() {
   mSlidingMenu.toggle();
 }
Beispiel #13
0
  public void onClick(View v) {
    // TODO Auto-generated method stub
    Intent intent = null;
    switch (v.getId()) {
      case R.id.seeallbtn:
        slidingMenu.toggle();
        break;

      case R.id.addnotebtn:
        intent = new Intent(MainActivity.this, AddNoteActivity.class);
        intent.putExtra("index", currentGroupIndex);
        startActivityForResult(intent, ADDNOTE);
        break;

      case R.id.addtype_btn:
        showDialog(ADDTYPE);
        break;

      case R.id.delete_btn_main:
        showDialog(SURE_DEL_NOTE);

        break;

      case R.id.share_btn_main:
        int which = 0; // 判断选中哪个一个记事本
        for (int i = 0; i < listAdapter.map.size(); i++) {
          if (listAdapter.map.get(i)) {
            which = i;
            break;
          }
        }

        // 通过which获取记事本的nid,再获取该记事本的基本信息
        NoteDetail noteDetail = noteDetailDao.getOneNote(noteList.get(which).get("nid").toString());

        intent = new Intent(Intent.ACTION_SEND);
        intent.setType("image/*");
        // 设置邮件默认标题
        intent.putExtra(Intent.EXTRA_SUBJECT, "我正在使用XNote超级记事本!");

        // 分享图片
        if (noteList.get(which).get("pic") != null) {
          File file = new File(Utils.PIC_PATH + noteList.get(which).get("pic"));
          intent.putExtra(Intent.EXTRA_STREAM, Uri.fromFile(file));
        }

        // 分享的内容
        intent.putExtra(Intent.EXTRA_TEXT, "我用XNote写了一篇记事:\n" + noteDetail.getContent());
        intent.setFlags(Intent.FLAG_ACTIVITY_NEW_TASK);
        // gettitle获取app的名字,显示在最上面
        startActivity(Intent.createChooser(intent, getTitle()));
        break;

      case R.id.move_btn_main:
        showDialog(SELECT_GROUP);
        break;

      case R.id.searchbtn_sidebar:
        if (listAdapter == null) {
          Toast.makeText(MainActivity.this, "暂无记事本,不能进行搜索服务", Toast.LENGTH_SHORT).show();
        } else {
          // 收取侧栏
          slidingMenu.toggle();
          toSearch();
        }

        break;

      case R.id.startsearch_btn:
        if (searchEditText.getText().toString().trim().equals("")) {
          searchEditText.setError("请输入内容");
        } else {
          String searchString = prepareSearch(searchEditText.getText().toString());

          System.out.println("组号----------" + currentGroupIndex);
          List<Map<String, Object>> searchList =
              noteDetailDao.getSearchResult(currentGroupIndex, searchString);
          if (searchList.size() > 0) {
            toNormal();
            // 让软键盘消失
            ((InputMethodManager) getSystemService(INPUT_METHOD_SERVICE))
                .hideSoftInputFromWindow(
                    MainActivity.this.getCurrentFocus().getWindowToken(),
                    InputMethodManager.HIDE_NOT_ALWAYS);
            showListView(searchList);

          } else {
            searchEditText.setError("对不起,无搜索结果");
          }
        }
        break;

      case R.id.calendarbtn_sidebar:
        // 收起侧栏
        slidingMenu.toggle();
        // 选中“全部”
        SelectOneType(0);
        intent = new Intent(MainActivity.this, CalendarActivity.class);
        startActivityForResult(intent, CALENDAR);

        break;

      case R.id.albumbtn_sidebar:
        PictureDao pictureDao = new PictureDao(this);
        if (pictureDao.checkHasPic()) {
          intent = new Intent(MainActivity.this, AlbumActivity.class);
          startActivity(intent);
        } else {
          Toast toast = Toast.makeText(this, "您的记事本中还没有添加相片哦!", Toast.LENGTH_SHORT);
          toast.setGravity(Gravity.CENTER, 0, 0);
          toast.show();
        }

        break;

      case R.id.passwdbtn_sidebar:

        // 查看用户是否设置过密码,若无则创建密码
        if (Utils.getPasswd(sharedPreferences) == null) {
          showDialog(CREATE_PASSWD);
        } else {
          intent = new Intent(MainActivity.this, EncryptSettingActivity.class);
          startActivity(intent);
        }

        break;

      case R.id.feedbackbtn_sidebar:
        agent.startFeedbackActivity();
        break;

      case R.id.shareappbtn_sidebar:
        // UMServiceFactory.shareTo(MainActivity.this,
        // "我使用了快速分享接口(UMServiceFactory.share)", null);

        // UMSocialService controller = UMServiceFactory.getUMSocialService(
        // MainActivity.class.getName(), RequestType.SOCIAL);
        umSocialService.setShareContent(
            "我正在使用一款功能强大的记事本XNote,个性化的工具和多媒体的记录让我爱不释手,你们也赶快去下载吧,各大安卓应用市场搜索“XNote”!"); // 设置分享文字内容

        // 设置分享图片
        UMImage shareImage = new UMImage(MainActivity.this, getString(R.string.poster_url));

        umSocialService.setShareMedia(shareImage);

        UMWXHandler.WX_APPID = "wxab4a81c9399bba08"; // 设置微信的Appid

        // 添加微信平台
        umSocialService.getConfig().supportWXPlatform(MainActivity.this);

        // 添加微信朋友圈
        umSocialService
            .getConfig()
            .supportWXPlatform(
                MainActivity.this,
                UMServiceFactory.getUMWXHandler(MainActivity.this).setToCircle(true));
        // 微信图文分享必须设置一个url,默认"http://www.umeng.com"
        UMWXHandler.CONTENT_URL = getString(R.string.poster_url);

        umSocialService.openShare(MainActivity.this, false);
        break;

      case R.id.aboutbtn_sidebar:
        intent = new Intent(MainActivity.this, AboutActivity.class);
        startActivity(intent);

        break;

      case R.id.voice_search_btn:
        // 显示语音输入提示框
        voiceRecognizerDialog.show();
        break;

      case R.id.changebtn:
        if (orderString.contains("asc")) {
          // 如果为顺序则改为逆序
          orderString = orderString.replace("asc", "desc");
        } else {
          // 如果为逆序则改为顺序
          orderString = orderString.replace("desc", "asc");
        }

        showListView();

        break;

      case R.id.locked_btn_main:

        // 查看用户是否设置过密码,若无则创建密码
        if (Utils.getPasswd(sharedPreferences) == null) {
          showDialog(CREATE_PASSWD);
        } else {
          for (int i = 0; i < listAdapter.map.size(); i++) {
            // 找出选中的记事本并加锁
            if (listAdapter.map.get(i)) {
              noteDetailDao.updateNoteLock(noteList.get(i).get("nid").toString(), 1);
            }
          }

          Toast.makeText(MainActivity.this, "加锁成功!", Toast.LENGTH_SHORT).show();
          // 回到正常模式
          toNormal();
          // 刷新列表
          showListView();
        }

        break;

      case R.id.unlocked_btn_main:
        boolean hasLocked = false;
        // 判断是否选中的记事本均未加锁
        for (int i = 0; i < listAdapter.map.size(); i++) {
          // 找出选中的记事本
          if (listAdapter.map.get(i)) {
            if (noteList.get(i).get("locked").toString().equals("1")) {
              hasLocked = true;
            }
          }
        }
        // 如果选中的都未加锁则直接返回
        if (!hasLocked) {
          Toast.makeText(MainActivity.this, "亲,没有加锁怎么解锁呢?!", Toast.LENGTH_SHORT).show();
          return;
        }

        AlertDialog.Builder builder = new AlertDialog.Builder(MainActivity.this);
        builder.setTitle("请输入密码进行解锁!");
        final EditText editText = new EditText(MainActivity.this);
        editText.setInputType(InputType.TYPE_TEXT_VARIATION_PASSWORD);
        editText.setHint("请输入密码");
        builder.setNegativeButton("取消", null);
        builder.setPositiveButton(
            "确定",
            new DialogInterface.OnClickListener() {

              public void onClick(DialogInterface dialog, int which) {
                // TODO Auto-generated method stub
                String passwdString = editText.getText().toString();
                // 密码正确
                if (passwdString.equals(Utils.getPasswd(sharedPreferences))) {
                  for (int i = 0; i < listAdapter.map.size(); i++) {
                    // 找出选中的记事本并解锁
                    if (listAdapter.map.get(i)) {
                      noteDetailDao.updateNoteLock(noteList.get(i).get("nid").toString(), 0);
                    }
                  }

                  Toast.makeText(MainActivity.this, "密码正确,解锁成功!", Toast.LENGTH_SHORT).show();

                  toNormal();
                  // 刷新列表
                  showListView();
                } else {
                  Toast.makeText(MainActivity.this, "密码错误,解锁失败!", Toast.LENGTH_SHORT).show();
                }
              }
            });

        builder.setView(editText);
        builder.show();

        break;
    }
  }