Java Code Examples for android.support.v7.app.AppCompatActivity#findViewById()

The following examples show how to use android.support.v7.app.AppCompatActivity#findViewById() . You can vote up the ones you like or vote down the ones you don't like, and go to the original project or source file by following the links above each example. You may check out the related API usage on the sidebar.
Example 1
Source File: UiUtils.java    From android-galaxyzoo with GNU General Public License v3.0 6 votes vote down vote up
static void showToolbar(final AppCompatActivity activity) {
    //The layout XML should include our toolbar.xml,
    //which we use instead of an ActionBar,
    //See also our use of <item name="windowActionBar">false</item> in styles.xml.
    final Toolbar toolbar = (Toolbar) activity.findViewById(R.id.toolbar);
    if (toolbar != null) {
        activity.setSupportActionBar(toolbar);

        //Remove the title text from the app bar (toolbar/actionbar)
        //because we instead use an icon that shows the title.
        final ActionBar actionBar = activity.getSupportActionBar();
        if (actionBar != null) {
            actionBar.setDisplayShowTitleEnabled(false);
        }

        //TODO: Why can't we specify this via android:logo in the XML:
        toolbar.setLogo(R.drawable.ic_toolbar_icon);
    }
}
 
Example 2
Source File: AndroidUtils.java    From go-bees with GNU General Public License v3.0 6 votes vote down vote up
/**
 * Setup toolbar.
 *
 * @param act    current activity.
 * @param isHome if it is home activity.
 * @param title  title.
 * @return ActionBar.
 */
public static ActionBar setUpToolbar(AppCompatActivity act, boolean isHome, int title) {
    Toolbar toolbar = (Toolbar) act.findViewById(R.id.toolbar);
    act.setSupportActionBar(toolbar);
    ActionBar ab = act.getSupportActionBar();
    if (ab != null) {
        ab.setDisplayHomeAsUpEnabled(true);
        if (isHome) {
            ab.setHomeAsUpIndicator(R.drawable.ic_menu);
            ab.setDisplayShowTitleEnabled(false);
        } else {
            ab.setDisplayShowHomeEnabled(true);
        }
        if (title != -1) {
            ab.setTitle(R.string.about_title);
        }
    }
    return ab;
}
 
Example 3
Source File: ShoppingListActivityCache.java    From privacy-friendly-shopping-list with Apache License 2.0 6 votes vote down vote up
public ShoppingListActivityCache(AppCompatActivity activity)
{
    this.activity = activity;

    listAdapter = new ListsAdapter(new ArrayList<>(), this);

    RecyclerView recyclerView = (RecyclerView) activity.findViewById(R.id.recyclerView);
    recyclerView.setLayoutManager(new LinearLayoutManager(activity));
    recyclerView.setAdapter(listAdapter);

    newListFab = (FloatingActionButton) activity.findViewById(R.id.fab_new_list);
    alertTextView = (LinearLayout) activity.findViewById(R.id.insert_alert);

    noListsLayout = (LinearLayout) activity.findViewById(R.id.no_lists_layout);

    recyclerView.addOnScrollListener(new FabScrollListenerForCreateActivities(newListFab));
}
 
Example 4
Source File: StatisticsCache.java    From privacy-friendly-shopping-list with Apache License 2.0 6 votes vote down vote up
public StatisticsCache(AppCompatActivity activity)
{
    this.activity = activity;

    titleTextView = (TextView) activity.findViewById(R.id.textview_stats_title);
    chart = (BarChart) activity.findViewById(R.id.chart);
    totalTextView = (TextView) activity.findViewById(R.id.textview_stats_total);

    unitsTextView = (TextView) activity.findViewById(R.id.textview_stats_currency);
    SharedPreferences prefs = PreferenceManager.getDefaultSharedPreferences(activity);
    String defaultCurrency = activity.getResources().getString(R.string.currency);
    currency = prefs.getString(SettingsKeys.CURRENCY, defaultCurrency);
    unitsTextView.setText(currency);

    rangeFromTextView = (TextView) activity.findViewById(R.id.textview_stats_range_from);
    rangeToTextView = (TextView) activity.findViewById(R.id.textview_stats_range_to);
    groupBySpinner = (Spinner) activity.findViewById(R.id.spinner_stats_group_by);
    valuesSpinner = (Spinner) activity.findViewById(R.id.spinner_stats_values);

    datePattern = activity.getResources().getString(R.string.date_short_pattern);
    dateLanguage = activity.getResources().getString(R.string.language);
    numberFormat = activity.getResources().getString(R.string.number_format_2_decimals);
}
 
Example 5
Source File: AbstractSubsequentActivity.java    From ShaderEditor with MIT License 5 votes vote down vote up
public static void initToolbar(AppCompatActivity activity) {
	Toolbar toolbar = (Toolbar) activity.findViewById(R.id.toolbar);
	activity.setSupportActionBar(toolbar);

	ActionBar actionBar = activity.getSupportActionBar();
	if (actionBar == null) {
		return;
	}
	actionBar.setDisplayHomeAsUpEnabled(true);
}
 
Example 6
Source File: ActionBarDecorator.java    From android-auto-call-recorder with MIT License 5 votes vote down vote up
/**
 * Setup the custom action bar (toolbar)
 *
 * @param appCompatActivity - the used activity
 */
public void setup(AppCompatActivity appCompatActivity) {
    ViewGroup rootView = (ViewGroup) appCompatActivity.findViewById(R.id.action_bar_root); //id from appcompat

    if (rootView != null) {
        View view = appCompatActivity.getLayoutInflater().inflate(R.layout.material_toolbar_layout, rootView, false);
        rootView.addView(view, 0);

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

    mActionBar = appCompatActivity.getSupportActionBar();

}
 
Example 7
Source File: SystemBarMetrics.java    From ShaderEditor with MIT License 5 votes vote down vote up
public static void initSystemBars(AppCompatActivity activity,
		Rect insets) {
	View mainLayout;
	if (activity != null &&
			(mainLayout = activity.findViewById(R.id.main_layout)) != null &&
			setSystemBarColor(
					activity.getWindow(),
					ShaderEditorApp.preferences.getSystemBarColor(),
					true)) {
		setWindowInsets(mainLayout, insets);
	}
}
 
Example 8
Source File: OAppBarUtils.java    From framework with GNU Affero General Public License v3.0 5 votes vote down vote up
public static void setAppBar(AppCompatActivity activity, Boolean withHomeButtonEnabled) {
    Toolbar toolbar = (Toolbar) activity.findViewById(R.id.toolbar);
    if (toolbar != null) {
        activity.setSupportActionBar(toolbar);
        ActionBar actionBar = activity.getSupportActionBar();
        if (withHomeButtonEnabled && actionBar != null) {
            actionBar.setHomeButtonEnabled(true);
            actionBar.setDisplayHomeAsUpEnabled(true);
        }
    }
}
 
Example 9
Source File: Results.java    From NoiseCapture with GNU General Public License v3.0 5 votes vote down vote up
public ReadRecordsProgression(AppCompatActivity activity) {
    this.activity = activity;
    progressView = activity.findViewById(R.id
            .result_progress_layout);
    progressBar = (ProgressBar) activity.findViewById(R.id
            .result_progress_control);
    button = (Button)activity.findViewById(R.id
            .result_progress_cancel);
    button.setOnClickListener(this);
}
 
Example 10
Source File: MapActivity.java    From NoiseCapture with GNU General Public License v3.0 5 votes vote down vote up
public ReadRecordsProgression(AppCompatActivity activity, AtomicBoolean canceled) {
    this.activity = activity;
    this.canceled = canceled;
    progressView = activity.findViewById(R.id
            .map_progress_layout);
    progressBar = (ProgressBar) activity.findViewById(R.id
            .map_progress_control);
    button = (Button)activity.findViewById(R.id
            .map_progress_cancel);
    button.setOnClickListener(this);
}
 
Example 11
Source File: OAppBarUtils.java    From hr with GNU Affero General Public License v3.0 5 votes vote down vote up
public static void setAppBar(AppCompatActivity activity, Boolean withHomeButtonEnabled) {
    Toolbar toolbar = (Toolbar) activity.findViewById(R.id.toolbar);
    if (toolbar != null) {
        activity.setSupportActionBar(toolbar);
        ActionBar actionBar = activity.getSupportActionBar();
        if (withHomeButtonEnabled && actionBar != null) {
            actionBar.setHomeButtonEnabled(true);
            actionBar.setDisplayHomeAsUpEnabled(true);
        }
    }
}
 
Example 12
Source File: ToolbarActivityHelper.java    From Nimingban with Apache License 2.0 5 votes vote down vote up
public static void setContentView(AppCompatActivity activity, @LayoutRes int layoutResID) {
    activity.setContentView(R.layout.activity_toolbar);

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

    ViewGroup content = (ViewGroup) activity.findViewById(R.id.content_panel);
    activity.getLayoutInflater().inflate(layoutResID, content);
    content.getChildAt(content.getChildCount() - 1).bringToFront();
}
 
Example 13
Source File: ThemeManager.java    From OneTapVideoDownload with GNU General Public License v3.0 5 votes vote down vote up
public static void applyTheme(AppCompatActivity activity) {
    activity.setTheme(ThemeManager.getTheme(activity));
    Toolbar toolbar = activity.findViewById(R.id.toolbar);
    toolbar.setBackgroundColor(ThemeManager.getPrimaryColor(activity));
    toolbar.setPopupTheme(getPopupMenuTheme(activity));
    if (android.os.Build.VERSION.SDK_INT >= Build.VERSION_CODES.LOLLIPOP) {
        activity.getWindow().setStatusBarColor(ThemeManager.getPrimaryDarkColor(activity));
        activity.getWindow().setNavigationBarColor(ThemeManager.getNavigationBarColor(activity));
    }
}
 
Example 14
Source File: TrendingRepositoryFragment.java    From gito-github-client with Apache License 2.0 5 votes vote down vote up
@Nullable
@Override
public View onCreateView(LayoutInflater inflater, @Nullable ViewGroup container,
                         @Nullable Bundle savedInstanceState) {
    View root = inflater.inflate(R.layout.fragment_trending, container, false);
    unbinder = ButterKnife.bind(this, root);

    int columnCount = getResources().getInteger(R.integer.grid_column_count);
    StaggeredGridLayoutManager staggeredGridLayoutManager =
            new StaggeredGridLayoutManager(columnCount, StaggeredGridLayoutManager.VERTICAL);
    mRecyclerView.setLayoutManager(staggeredGridLayoutManager);

    mAdapter = new TrendingRepositoryListAdapter(null, this);
    mAdapter.setHasStableIds(true);
    mRecyclerView.setAdapter(mAdapter);

    if (getActivity() instanceof AppCompatActivity) {
        AppCompatActivity activity = (AppCompatActivity) getActivity();
        if (activity.getSupportActionBar() != null) {
            activity.getSupportActionBar().setTitle(mPresenter.getTitle(getContext()));
        }
        mCoordinatorLayout = activity.findViewById(R.id.coordinator_layout);
        setUpBadges();
    }

    setUpBottomNavigationBar();

    mPresenter.start(savedInstanceState);
    return root;
}
 
Example 15
Source File: ToolbarHelper.java    From FriendBook with GNU General Public License v3.0 5 votes vote down vote up
public static Toolbar initToolbar(@NonNull final AppCompatActivity activity, @IdRes int toolbarId, boolean canBack, @Nullable CharSequence title) {
    Toolbar toolbar = (Toolbar) activity.findViewById(toolbarId);
    if (toolbar == null) {
        throw new IllegalStateException(
                "The subclass of ToolbarActivity must contain a toolbar.");
    }
    activity.setSupportActionBar(toolbar);
    ActionBar actionBar = activity.getSupportActionBar();
    if (actionBar != null) {
        if (canBack) {
            actionBar.setDisplayHomeAsUpEnabled(true);
            if (title != null) {
                actionBar.setTitle(title);
            } else {
                actionBar.setDisplayShowTitleEnabled(false);
            }
            toolbar.setNavigationOnClickListener(new View.OnClickListener() {
                @Override
                public void onClick(View v) {
                    activity.onBackPressed();
                }
            });
        }

    }
    return toolbar;
}
 
Example 16
Source File: TestUtils.java    From Awesome-WanAndroid with Apache License 2.0 5 votes vote down vote up
public static String getToolBarNavigationContentDescription(@NonNull AppCompatActivity mActivity,
                                                            @NonNull @IdRes int mToolbarId) {
    Toolbar toolbar = (Toolbar) mActivity.findViewById(mToolbarId);
    if (toolbar != null) {
        return (String) toolbar.getNavigationContentDescription();
    } else {
        throw new RuntimeException("Toolbar is null!");
    }
}
 
Example 17
Source File: TapIntroHelper.java    From candybar-library with Apache License 2.0 4 votes vote down vote up
public static void showIconsIntro(@NonNull Context context) {
    if (Preferences.get(context).isTimeToShowIconsIntro()) {
        AppCompatActivity activity = (AppCompatActivity) context;

        Toolbar toolbar = activity.findViewById(R.id.toolbar);
        if (toolbar == null) return;

        new Handler().postDelayed(() -> {
            try {
                int primary = ColorHelper.getAttributeColor(context, R.attr.toolbar_icon);
                int secondary = ColorHelper.setColorAlpha(primary, 0.7f);

                Typeface title = TypefaceHelper.getMedium(context);
                Typeface description = TypefaceHelper.getRegular(context);

                TapTarget tapTarget = TapTarget.forToolbarMenuItem(toolbar, R.id.menu_search,
                        context.getResources().getString(R.string.tap_intro_icons_search),
                        context.getResources().getString(R.string.tap_intro_icons_search_desc))
                        .titleTextColorInt(primary)
                        .descriptionTextColorInt(secondary)
                        .targetCircleColorInt(primary)
                        .drawShadow(Preferences.get(context).isTapIntroShadowEnabled());

                if (title != null) {
                    tapTarget.textTypeface(title);
                }

                //if (description != null) {
                //tapTarget.descriptionTypeface(description);
                //}

                TapTargetView.showFor(activity, tapTarget,
                        new TapTargetView.Listener() {

                            @Override
                            public void onTargetDismissed(TapTargetView view, boolean userInitiated) {
                                super.onTargetDismissed(view, userInitiated);
                                Preferences.get(context).setTimeToShowIconsIntro(false);
                            }
                        });
            } catch (Exception e) {
                LogUtil.e(Log.getStackTraceString(e));
            }
        }, 100);
    }
}
 
Example 18
Source File: MorphyToolbar.java    From morphy-toolbar with MIT License 4 votes vote down vote up
public static MorphyToolbar findInActivity(@NonNull AppCompatActivity activity) {
    return (MorphyToolbar) activity.findViewById(R.id.mt_morphy_toolbar);
}
 
Example 19
Source File: ToolbarSupport.java    From DebugOverlay-Android with Apache License 2.0 4 votes vote down vote up
public static Toolbar getToolbar(AppCompatActivity activity) {
    return (Toolbar) activity.findViewById(R.id.toolbar);
}