Example usage for android.app ActionBar setTitle

List of usage examples for android.app ActionBar setTitle

Introduction

In this page you can find the example usage for android.app ActionBar setTitle.

Prototype

public abstract void setTitle(@StringRes int resId);

Source Link

Document

Set the action bar's title.

Usage

From source file:de.da_sense.moses.client.DetailFragment.java

/**
 * Initializes the button logic/*from ww w  .j  a  v a 2s. c  o  m*/
 */
private void initializeButtons() {
    ActionBar ab = mActivity.getActionBar();
    if (mBelongsTo == AVAILABLE) {
        ab.setTitle(getString(R.string.userStudy_available));
        // get start button
        Button button = (Button) mDetailFragmentView.findViewById(R.id.startapp);
        // change the text of it to install
        button.setText(getString(R.string.install));
        // make an action listener for it
        button.setOnClickListener(new OnClickListener() {
            @Override
            public void onClick(View v) {
                ExternalApplication app = AvailableFragment.getInstance().getExternalApps().get(mIndex);// getShownIndex());
                Log.d(LOG_TAG, "installing app ( " + app.getName() + " ) with apkid = " + app.getID());
                AvailableFragment.getInstance().handleInstallApp(app);
            }
        });
        // get update button
        button = (Button) mDetailFragmentView.findViewById(R.id.update);
        button.setVisibility(View.GONE); // there is no update
        // for
        // this new app
        // get questionnaire button
        button = (Button) mDetailFragmentView.findViewById(R.id.btn_questionnaire);
        button.setVisibility(View.GONE); // there is no
        // questionnaire for
        // this new app
    } else if (mBelongsTo == RUNNING) {
        ab.setTitle(getString(R.string.userStudy_running));
        // get start button
        Button button = (Button) mDetailFragmentView.findViewById(R.id.startapp);
        Button updateButton = (Button) mDetailFragmentView.findViewById(R.id.update);
        updateButton.setVisibility(
                RunningFragment.getInstance().getInstalledApps().get(getShownIndex()).getUpdateAvailable()
                        ? View.VISIBLE
                        : View.GONE);
        // change the text of it to install
        button.setText(getString(R.string.open));
        // make an action listener for it
        button.setOnClickListener(new OnClickListener() {
            @Override
            public void onClick(View v) {
                InstalledExternalApplication app = RunningFragment.getInstance().getInstalledApps().get(mIndex);// getShownIndex());
                Log.d(LOG_TAG, "open app ( " + app.getName() + " ) with apkid = " + app.getID());
                RunningFragment.getInstance().handleStartApp(app);
            }
        });
        // get questionnaire button, if the questionnaire is not
        // yet
        // sent
        button = (Button) mDetailFragmentView.findViewById(R.id.btn_questionnaire);
        // check if it has Questionnaire and if it's sent
        if (InstalledExternalApplicationsManager.getInstance() == null)
            InstalledExternalApplicationsManager.init(MosesService.getInstance());
        InstalledExternalApplication app = InstalledExternalApplicationsManager.getInstance()
                .getAppForId(mAPKID);
        Log.d(LOG_TAG, "app = " + app);
        if (app != null) {
            final boolean hasSurveyLocal = app.hasSurveyLocally();
            boolean isQuestionnaireSent = hasSurveyLocal ? app.getSurvey().hasBeenSent() : false;
            Log.d(LOG_TAG, "hasQuestLocal" + hasSurveyLocal + "isQuestSent" + isQuestionnaireSent);
            // set button according to the booleans
            if (isQuestionnaireSent) {
                button.setText(getString(R.string.details_running_questionnairesent));
                button.setClickable(false);
                button.setEnabled(false);
            } else {

                if (hasSurveyLocal) {
                    button.setText(getString(R.string.btn_survey));
                    button.setClickable(true);
                    button.setEnabled(true);
                } else {
                    button.setText(getString(R.string.download_survey));
                    if (AsyncGetSurvey.isRunning()) {
                        // disable the button, the async task is
                        // still waiting for the survey
                        button.setEnabled(false);
                    } else {
                        if (!app.getEndDateReached()) {
                            // the button should be disabled because the end date has still not been reached
                            button.setEnabled(false);
                        }
                    }
                }

                button.setOnClickListener(new OnClickListener() {
                    @Override
                    public void onClick(View v) {
                        if (hasSurveyLocal) {
                            startSurveyActivity(mAPKID);
                        } else {
                            Log.d(LOG_TAG, "Getting Questionnaire from Server");
                            v.setEnabled(false); // disable the
                                                 // button
                            Toaster.showToast(mActivity, getString(R.string.notification_downloading_survey));
                            AsyncGetSurvey getSurveyAsyncTask = new AsyncGetSurvey();
                            InstalledExternalApplicationsManager.getInstance().getAppForId(mAPKID)
                                    .getQuestionnaireFromServer();
                            getSurveyAsyncTask.execute(mAPKID);
                        }
                    }
                });
            }
            // get update button
            boolean updateAvailable = InstalledExternalApplicationsManager.getInstance().getAppForId(mAPKID)
                    .isUpdateAvailable();
            button = (Button) mDetailFragmentView.findViewById(R.id.update);
            if (updateAvailable) {
                button.setVisibility(View.VISIBLE);
                button.setOnClickListener(new OnClickListener() {

                    @Override
                    public void onClick(View v) {
                        AvailableFragment.getInstance().handleInstallApp(
                                InstalledExternalApplicationsManager.getInstance().getAppForId(mAPKID));
                    }
                });
                // make the label of survey button shorter
                Button surveyButton = (Button) mDetailFragmentView.findViewById(R.id.btn_questionnaire);
                surveyButton.setText(getString(R.string.btn_survey_short));
            } else {
                button.setVisibility(View.GONE);
            }
        }
    } else if (mBelongsTo == HISTORY) {
        ab.setTitle(getString(R.string.userStudy_past));
        // get start button
        Button button = (Button) mDetailFragmentView.findViewById(R.id.startapp);
        button.setVisibility(View.GONE); // hide open / install
        // button
        // get update button
        button = (Button) mDetailFragmentView.findViewById(R.id.update);
        button.setVisibility(View.GONE); // there is no update
        // for
        // this old app
        // get questionnaire button, if the questionnaire is not
        // yet
        // sent
        button = (Button) mDetailFragmentView.findViewById(R.id.btn_questionnaire);
        button.setVisibility(View.GONE);
        // check if it has Questionnaire and if it's sent
        if (HistoryExternalApplicationsManager.getInstance() == null)
            HistoryExternalApplicationsManager.init(MosesService.getInstance());
        boolean hasQuestionnaire = HistoryExternalApplicationsManager.getInstance().getAppForId(mAPKID)
                .hasSurveyLocally();
        //         boolean isQuestionnaireSent = hasQuestionnaire ? HistoryExternalApplicationsManager
        //               .getInstance().getAppForId(mAPKID).getSurvey()
        //               .hasBeenSent()
        //               : true;
        // set button according to the booleans
        if (!hasQuestionnaire) {
            button.setText(getString(R.string.details_running_noquestionnaire));
            button.setClickable(false);
            button.setEnabled(false);
        }
        //         else if (isQuestionnaireSent) {
        //            button.setText(getString(R.string.details_running_questionnairesent));
        //            button.setClickable(false);
        //            button.setEnabled(false);
        //         } 
        else {
            // we have Survey
            button.setVisibility(View.VISIBLE);
            button.setOnClickListener(new OnClickListener() {
                @Override
                public void onClick(View v) {
                    Intent intent = new Intent();
                    intent.setClass(mActivity, SurveyActivity.class);
                    intent.putExtra(ExternalApplication.KEY_APK_ID, mAPKID);
                    intent.putExtra(WelcomeActivity.KEY_BELONGS_TO, HISTORY);
                    startActivity(intent);
                }
            });
        }
    }
}

From source file:com.aniruddhc.acemusic.player.MusicLibraryEditorActivity.MusicLibraryEditorActivity.java

@Override
public boolean onCreateOptionsMenu(Menu menu) {
    MenuInflater inflater = getMenuInflater();
    inflater.inflate(R.menu.add_to_music_library, menu);

    ActionBar actionBar = getActionBar();
    actionBar.setBackgroundDrawable(UIElementsHelper.getGeneralActionBarBackground(mContext));
    actionBar.setIcon(/*from   w ww.j a  v  a  2s .co  m*/
            mContext.getResources().getIdentifier(libraryIconName, "drawable", mContext.getPackageName()));
    SpannableString s = new SpannableString(libraryName);
    s.setSpan(new TypefaceSpan(this, "RobotoCondensed-Light"), 0, s.length(),
            Spannable.SPAN_EXCLUSIVE_EXCLUSIVE);
    actionBar.setTitle(s);

    return super.onCreateOptionsMenu(menu);
}

From source file:com.alcoapps.navigationdrawer.NavdrawerModule.java

@Kroll.method
public void attach() {
    // as a first step I'll play around with the actual activity and actionbar to make sure
    // I can properly get access to it

    // some feedback is always nice
    Log.d(TAG, "called the attach method");

    // declare stuff
    TiApplication appContext = TiApplication.getInstance();
    Activity activity = appContext.getCurrentActivity();
    ActionBar actionBar;

    if (!TiApplication.isUIThread()) {

        // Within which the entire activity is enclosed
        //DrawerLayout mDrawerLayout;

        // ListView represents Navigation Drawer
        //ListView mDrawerList;

        // ActionBarDrawerToggle indicates the presence of Navigation Drawer in the action bar
        //ActionBarDrawerToggle mDrawerToggle;

        // Play with the action bar
        String mTitle = "This is a test";
        String mSubtitle = "This is the subtitle";

        actionBar = activity.getActionBar();
        actionBar.setDisplayHomeAsUpEnabled(true);
        actionBar.setSubtitle(mSubtitle);
        actionBar.setTitle(mTitle);
    }//from  w w  w .  ja v a  2  s.  c  o  m
}

From source file:com.android.contacts.activities.ContactDetailActivity.java

/**
 * Setup the activity title and subtitle with contact name and company.
 *//*from  w  w w  . j  ava 2 s .  c o  m*/
private void setupTitle() {
    CharSequence displayName = ContactDetailDisplayUtils.getDisplayName(this, mContactData);
    String company = ContactDetailDisplayUtils.getCompany(this, mContactData);

    ActionBar actionBar = getActionBar();
    actionBar.setTitle(displayName);
    actionBar.setSubtitle(company);

    final StringBuilder talkback = new StringBuilder();
    if (!TextUtils.isEmpty(displayName)) {
        talkback.append(displayName);
    }
    if (!TextUtils.isEmpty(company)) {
        if (talkback.length() != 0) {
            talkback.append(", ");
        }
        talkback.append(company);
    }

    if (talkback.length() != 0) {
        AccessibilityManager accessibilityManager = (AccessibilityManager) this
                .getSystemService(Context.ACCESSIBILITY_SERVICE);
        if (accessibilityManager.isEnabled()) {
            View decorView = getWindow().getDecorView();
            decorView.setContentDescription(talkback);
            decorView.sendAccessibilityEvent(AccessibilityEvent.TYPE_WINDOW_STATE_CHANGED);
        }
    }
}

From source file:fr.cph.chicago.activity.MainActivity.java

/**
 * Restore action bar/* ww w.  j  a  v a2s .co m*/
 */
public final void restoreActionBar() {
    ActionBar actionBar = getActionBar();
    actionBar.setNavigationMode(ActionBar.NAVIGATION_MODE_STANDARD);
    actionBar.setDisplayShowTitleEnabled(true);
    actionBar.setTitle(mTitle);
}

From source file:name.gumartinm.weather.information.activity.MainTabsActivity.java

@Override
public void onResume() {
    super.onResume();

    final SharedPreferences sharedPreferences = PreferenceManager
            .getDefaultSharedPreferences(this.getApplicationContext());

    final String APPID = sharedPreferences.getString(this.getString(R.string.weather_preferences_app_id_key),
            "");//  w  ww  . j a  v  a  2  s  .  c  om

    final String noticeKeyPreference = this.getString(R.string.api_id_key_notice_preference_key);
    final boolean notice = sharedPreferences.getBoolean(noticeKeyPreference, true);

    if (notice && APPID.isEmpty()) {
        final FragmentManager fm = this.getSupportFragmentManager();
        final Fragment buttonsFragment = fm.findFragmentByTag("noticeDialog");
        if (buttonsFragment == null) {
            final DialogFragment newFragment = APIKeyNoticeDialogFragment
                    .newInstance(R.string.api_id_key_notice_title);
            newFragment.setRetainInstance(true);
            newFragment.setCancelable(false);
            newFragment.show(fm, "noticeDialog");
        }
    }

    final ActionBar actionBar = this.getActionBar();

    // 1. Update title.
    final DatabaseQueries query = new DatabaseQueries(this.getApplicationContext());
    final WeatherLocation weatherLocation = query.queryDataBase();
    if (weatherLocation != null) {
        final String[] array = new String[2];
        array[0] = weatherLocation.getCity();
        array[1] = weatherLocation.getCountry();
        final MessageFormat message = new MessageFormat("{0},{1}", Locale.US);
        final String cityCountry = message.format(array);
        actionBar.setTitle(cityCountry);
    } else {
        actionBar.setTitle(this.getString(R.string.text_field_no_chosen_location));
    }

    // 2. Update forecast tab text.
    final String keyPreference = this.getString(R.string.weather_preferences_day_forecast_key);
    final String value = sharedPreferences.getString(keyPreference, "");
    String humanValue = "";
    if (value.equals(this.getString(R.string.weather_preferences_day_forecast_five_day))) {
        humanValue = this.getString(R.string.text_tab_five_days_forecast);
    } else if (value.equals(this.getString(R.string.weather_preferences_day_forecast_ten_day))) {
        humanValue = this.getString(R.string.text_tab_ten_days_forecast);
    } else if (value.equals(this.getString(R.string.weather_preferences_day_forecast_fourteen_day))) {
        humanValue = this.getString(R.string.text_tab_fourteen_days_forecast);
    }
    actionBar.getTabAt(1).setText(humanValue);
}

From source file:com.retroteam.studio.retrostudio.EditorLandscape.java

/**
 * Set up the {@link android.app.ActionBar}, if the API is available.
 */// w ww . java 2s .  c  o  m
@TargetApi(Build.VERSION_CODES.HONEYCOMB)
private void setupActionBar(String title) {
    if (Build.VERSION.SDK_INT >= Build.VERSION_CODES.HONEYCOMB) {
        // Show the Up button in the action bar.
        ActionBar editorbar = getActionBar();
        editorbar.setDisplayHomeAsUpEnabled(true);
        editorbar.setTitle(title);

    }
}

From source file:com.concentricsky.android.khanacademy.app.ManageDownloadsActivity.java

@Override
protected void onStart() {
    super.onStart();

    gridView = (GridView) findViewById(R.id.grid);
    gridView.setChoiceMode(AbsListView.CHOICE_MODE_MULTIPLE_MODAL);
    gridView.setMultiChoiceModeListener(multiChoiceModeListener);
    gridView.setOnItemClickListener(itemClickListener);

    View emptyView = getLayoutInflater().inflate(R.layout.listview_empty, null, false);
    ((TextView) emptyView.findViewById(R.id.text_list_empty)).setText(R.string.msg_no_downloaded_videos);
    ViewGroup.LayoutParams p = new ViewGroup.LayoutParams(ViewGroup.LayoutParams.MATCH_PARENT,
            ViewGroup.LayoutParams.MATCH_PARENT);
    addContentView(emptyView, p);//from ww  w .  ja v  a 2 s .  co m

    gridView.setEmptyView(emptyView);

    requestDataService(new ObjectCallback<KADataService>() {
        @Override
        public void call(final KADataService dataService) {
            ManageDownloadsActivity.this.dataService = dataService;

            CursorAdapter adapter = new Adapter(ManageDownloadsActivity.this, null, 0,
                    dataService.getThumbnailManager());
            gridView.setAdapter(adapter);

            new AsyncTask<Void, Void, Cursor>() {
                @Override
                protected Cursor doInBackground(Void... arg) {
                    return getCursor();
                }

                @Override
                protected void onPostExecute(Cursor cursor) {
                    ((CursorAdapter) gridView.getAdapter()).changeCursor(cursor);
                }
            }.executeOnExecutor(AsyncTask.THREAD_POOL_EXECUTOR);

            final ActionBar ab = getActionBar();
            ab.setDisplayHomeAsUpEnabled(true);

            ab.setNavigationMode(ActionBar.NAVIGATION_MODE_LIST);
            ab.setTitle("");

            setupListNavigation();

            // The receiver performs actions that require a dataService, so register it here.
            IntentFilter filter = new IntentFilter();
            filter.addAction(ACTION_LIBRARY_UPDATE);
            filter.addAction(ACTION_BADGE_EARNED);
            filter.addAction(ACTION_OFFLINE_VIDEO_SET_CHANGED);
            filter.addAction(ACTION_DOWNLOAD_PROGRESS_UPDATE);
            filter.addAction(ACTION_TOAST);
            broadcastManager.registerReceiver(receiver, filter);
        }
    });
}

From source file:com.cairoconfessions.MainActivity.java

public void restoreActionBar() {
    ActionBar actionBar = getActionBar();
    actionBar.setNavigationMode(ActionBar.NAVIGATION_MODE_STANDARD);
    actionBar.setDisplayShowTitleEnabled(true);
    if (mTitle != "Cairo Confessions")
        actionBar.setTitle(mTitle);
}

From source file:fr.tvbarthel.attempt.googlyzooapp.MainActivity.java

public void restoreActionBar() {
    ActionBar actionBar = getActionBar();
    actionBar.setNavigationMode(ActionBar.NAVIGATION_MODE_STANDARD);
    actionBar.setDisplayShowTitleEnabled(true);
    actionBar.setTitle(mTitle);
    actionBar.setIcon(mActionBarIcon);/*from w ww. ja v a  2s .com*/
}