Beispiel #1
0
  @Override
  protected void onCreate(Bundle savedInstanceState) {
    super.onCreate(savedInstanceState);
    setContentView(R.layout.activity_main);
    UmengUpdateAgent.setDefault();
    UmengUpdateAgent.update(this);
    Toolbar toolbar = (Toolbar) findViewById(R.id.toolbar);
    setSupportActionBar(toolbar);

    mDrawerLayout = (ViewGroup) findViewById(R.id.drawer_layout);
    mNavigationDrawerFragment =
        (NavigationDrawerFragment) getFragmentManager().findFragmentById(R.id.left_drawer);
    mTitle = getTitle();

    mFavoriteTabTitles = getResources().getStringArray(R.array.v2ex_favorite_tab_titles);
    mFavoriteTabPaths = getResources().getStringArray(R.array.v2ex_favorite_tab_paths);
    mMainTitles = getResources().getStringArray(R.array.v2ex_nav_main_titles);

    mSpinnerAdapter = new SpinnerAdapter(this, mFavoriteTabTitles);

    ActionBar supportActionBar = getSupportActionBar();
    supportActionBar.setCustomView(R.layout.actionbar_custom_spinner);
    mActionbarCustom = supportActionBar.getCustomView();
    Spinner spinner = (Spinner) supportActionBar.getCustomView().findViewById(R.id.spinner);
    spinner.setAdapter(mSpinnerAdapter);
    //        spinner.setOnItemSelectedListener(new AdapterView.OnItemSelectedListener() {
    //            @Override
    //            public void onItemSelected(AdapterView<?> parent, View view, int position, long
    // id) {
    //                TopicsFragment fragment = new TopicsFragment();
    //                Bundle bundle = new Bundle();
    //                mSpinnerAdapter.setCheckPos(position);
    //                bundle.putString("tab", mFavoriteTabPaths[position]);
    //                bundle.putBoolean("attach_main", true);
    //                bundle.putBoolean("show_menu", false);
    //                fragment.setArguments(bundle);
    //
    //                FragmentTransaction fragmentTransaction =
    // getFragmentManager().beginTransaction();
    //                fragmentTransaction.replace(R.id.container, fragment,
    // mFavoriteTabTitles[position]).commit();
    //            }
    //
    //            @Override
    //            public void onNothingSelected(AdapterView<?> parent) {
    //
    //            }
    //        });

    // Set up the drawer.
    mNavigationDrawerFragment.setUp(
        R.id.left_drawer, (DrawerLayout) findViewById(R.id.drawer_layout));

    // ActionBar actionBar = getSupportActionBar();
    // actionBar.setDisplayHomeAsUpEnabled(true);
    // actionBar.setHomeButtonEnabled(true);
    // actionBar.setDisplayShowTitleEnabled(true);

    if (mIsLogin) initAccount();
  }
  @Override
  public void applySelfActionBar() {
    if (parentActivity == null) {
      return;
    }
    ActionBar actionBar = parentActivity.getSupportActionBar();
    actionBar.setDisplayShowCustomEnabled(true);
    actionBar.setDisplayShowHomeEnabled(false);
    actionBar.setDisplayShowTitleEnabled(false);
    actionBar.setDisplayHomeAsUpEnabled(false);

    actionBar.setCustomView(R.layout.settings_do_action_layout);
    View cancelButton = actionBar.getCustomView().findViewById(R.id.cancel_button);
    cancelButton.setOnClickListener(
        new View.OnClickListener() {
          @Override
          public void onClick(View view) {
            finishFragment();
          }
        });
    doneButton = actionBar.getCustomView().findViewById(R.id.done_button);
    doneButton.setOnClickListener(
        new View.OnClickListener() {
          @Override
          public void onClick(View view) {
            if (firstNameField.getText().length() != 0) {
              saveName();
              finishFragment();
            }
          }
        });
  }
  private void initTitleBar() {
    mSpinnerAdapter = new MySpinnerAdapter(getLayoutInflater());

    Toolbar toolbar = (Toolbar) findViewById(R.id.toolbar);
    setSupportActionBar(toolbar);

    ActionBar supportActionBar = getSupportActionBar();
    supportActionBar.setDisplayHomeAsUpEnabled(true);
    supportActionBar.setDisplayShowHomeEnabled(true);
    supportActionBar.setHomeButtonEnabled(true);
    supportActionBar.setTitle("");
    supportActionBar.setDisplayShowCustomEnabled(true);

    supportActionBar.setCustomView(R.layout.actionbar_custom_spinner);
    Spinner spinner = (Spinner) supportActionBar.getCustomView().findViewById(R.id.spinner);
    spinner.setAdapter(mSpinnerAdapter);
    spinner.setOnItemSelectedListener(
        new AdapterView.OnItemSelectedListener() {

          @Override
          public void onItemSelected(AdapterView<?> parent, View view, int position, long id) {
            mSpinnerAdapter.setCheckPos(position);
            changePageShow(position);
          }

          @Override
          public void onNothingSelected(AdapterView<?> parent) {}
        });
  }
Beispiel #4
0
  // Comportement de la partie search dans l'appBar
  protected void handleMenuSearch() {
    ActionBar action = getSupportActionBar(); // get the actionbar

    if (isSearchOpened) { // test if the search is open

      action.setDisplayShowCustomEnabled(false); // disable a custom view inside the actionbar
      action.setDisplayShowTitleEnabled(true); // show the title in the action bar

      // hides the keyboard
      InputMethodManager imm = (InputMethodManager) getSystemService(Context.INPUT_METHOD_SERVICE);
      imm.hideSoftInputFromWindow(edtSeach.getWindowToken(), 0);

      // add the search icon in the action bar
      mSearchAction.setIcon(getResources().getDrawable(R.drawable.ic_menu_search));

      isSearchOpened = false;
    } else { // open the search entry

      action.setDisplayShowCustomEnabled(true); // enable it to display a
      // custom view in the action bar.
      action.setCustomView(R.layout.search_bar); // add the custom view
      action.setDisplayShowTitleEnabled(false); // hide the title

      edtSeach =
          (EditText)
              action.getCustomView().findViewById(R.id.searchBar_editText); // the text editor

      // this is a listener to do a search when the user clicks on search button
      edtSeach.setOnEditorActionListener(
          new TextView.OnEditorActionListener() {
            @Override
            public boolean onEditorAction(TextView v, int actionId, KeyEvent event) {
              if (actionId == EditorInfo.IME_ACTION_SEARCH) {
                doSearch();
                return true;
              }
              return false;
            }
          });

      edtSeach.requestFocus();

      // open the keyboard focused in the edtSearch
      InputMethodManager imm = (InputMethodManager) getSystemService(Context.INPUT_METHOD_SERVICE);
      imm.showSoftInput(edtSeach, InputMethodManager.SHOW_IMPLICIT);

      // add the close icon
      mSearchAction.setIcon(getResources().getDrawable(R.drawable.ic_menu_search));

      isSearchOpened = true;
    }
  }
  private void setTitleBar() {
    ActionBar actionBar = getSupportActionBar();
    actionBar.setDisplayOptions(ActionBar.DISPLAY_SHOW_CUSTOM);
    actionBar.setCustomView(R.layout.actionbar_title);
    actionBar.setElevation(0);

    int actionbarcolor = getResources().getColor(R.color.background_title);
    actionBar.setBackgroundDrawable(new ColorDrawable(actionbarcolor));
    actionBar.setDisplayHomeAsUpEnabled(true);
    TextView title =
        (TextView) actionBar.getCustomView().findViewById(R.id.actionbar_title_textview);
    title.setText("Confirm");
  }
Beispiel #6
0
  @Override
  public void onAttach(Activity activity) {
    super.onAttach(activity);

    mActionBar = ((AppCompatActivity) activity).getSupportActionBar();

    if (activity instanceof MainActivity) {
      mActionBar
          .getCustomView()
          .setOnClickListener(
              new View.OnClickListener() {
                @Override
                public void onClick(View v) {
                  onActionBarClick();
                }
              });
    }
  }
  @Override
  protected void onCreate(Bundle savedInstanceState) {
    super.onCreate(savedInstanceState);
    setContentView(R.layout.activity_compose_tweet);
    // get user data from shared prefferences
    sharedpreferences = this.getSharedPreferences(CURRENT_USER_PREFERECES, 0);
    final String uName = sharedpreferences.getString(userName, "missing");
    final String uScreenName = sharedpreferences.getString(userScreenName, "missing");
    final String uPicUrl = sharedpreferences.getString(userPicUrl, "missing");

    // set up views
    tv_userName = (TextView) findViewById(R.id.tv_user_name_compose);
    tv_userScreenName = (TextView) findViewById(R.id.tv_user_screen_name_compose);
    iv_userProfilePic = (ImageView) findViewById(R.id.iv_profile_pic_compose);
    et_tweetText = (EditText) findViewById(R.id.tv_tweet_text);

    // setting user name and user screen name
    tv_userName.setText(uName);
    tv_userScreenName.setText(uScreenName);
    // setting user pic
    iv_userProfilePic.setImageResource(0);
    Picasso.with(this).load(uPicUrl).into(iv_userProfilePic);

    // action bar settings
    ActionBar actionBar = getSupportActionBar();
    actionBar.setDisplayOptions(ActionBar.DISPLAY_SHOW_CUSTOM);
    actionBar.setCustomView(R.layout.custom_compose_action_bar);

    // find char count Text view
    final View customActionBarView = actionBar.getCustomView();
    final TextView tv_chCount = (TextView) customActionBarView.findViewById(R.id.tvCharCount_t);
    tv_chCount.setText("0");

    // find button tweet
    final Button bt_tweet = (Button) customActionBarView.findViewById(R.id.btnTweet_t);

    // set back button listener
    customActionBarView
        .findViewById(R.id.ivCancel_t)
        .setOnClickListener(
            new View.OnClickListener() {
              @Override
              public void onClick(View v) {

                finish();
              }
            });

    // set tweet button listener
    bt_tweet.setOnClickListener(
        new View.OnClickListener() {
          @Override
          public void onClick(View v) {
            if (!isNetworkAvailable()) {
              buildDialog(ComposeTweetActivity.this).show();
            } else {
              String tweetBody = et_tweetText.getText().toString();
              client = TwitterApplication.getRestClient();
              client.postTweet(
                  new JsonHttpResponseHandler() {

                    @Override
                    public void onSuccess(int statusCode, Header[] headers, JSONObject response) {
                      Log.d(COMPOSE_TWEET_ACTIVITY_TAG, response.toString());
                      Tweet tweet = new Tweet();
                      tweet = Tweet.fromJsonObject(response, "home");
                      Intent i = new Intent();
                      i.putExtra("newTweet", tweet);
                      setResult(RESULT_OK, i);
                      finish();
                    }

                    @Override
                    public void onFailure(
                        int statusCode,
                        Header[] headers,
                        String responseString,
                        Throwable throwable) {
                      // add some messaging
                    }
                  },
                  tweetBody);
            }
          }
        });

    et_tweetText.addTextChangedListener(
        new TextWatcher() {
          @Override
          public void onTextChanged(CharSequence s, int start, int before, int count) {

            if (s.length() > 140) {
              tv_chCount.setTextColor(Color.RED);
              bt_tweet.setBackgroundColor(Color.GRAY);
              bt_tweet.setEnabled(false);
            } else {
              tv_chCount.setTextColor(getResources().getColor(R.color.dark_gray));
              bt_tweet.setEnabled(true);
              bt_tweet.setBackgroundColor(getResources().getColor(R.color.skyblue));
            }
            tv_chCount.setText(String.valueOf(s.length()));
          }

          @Override
          public void beforeTextChanged(CharSequence s, int start, int count, int after) {}

          @Override
          public void afterTextChanged(Editable s) {}
        });
  }