Java Code Examples for android.support.v7.app.AppCompatDelegate

The following are top voted examples for showing how to use android.support.v7.app.AppCompatDelegate. These examples are extracted from open source projects. You can vote up the examples you like and your votes will be used in our system to generate more good examples.
Example 1
Project: SuperToast   File: MainActivity.java   View source code 6 votes vote down vote up
private void initView() {
    AppCompatDelegate.setCompatVectorFromResourcesEnabled(true);
    bt1 = findViewById(R.id.main_button1);
    bt2 = findViewById(R.id.main_button2);
    bt3 = findViewById(R.id.main_button3);

    bt4 = findViewById(R.id.main_button4);
    bt5 = findViewById(R.id.main_button5);
    bt6 = findViewById(R.id.main_button6);

    bt7 = findViewById(R.id.main_button7);
    bt8 = findViewById(R.id.main_button8);
    bt9 = findViewById(R.id.main_button9);

    bt1.setOnClickListener(this);
    bt2.setOnClickListener(this);
    bt3.setOnClickListener(this);

    bt4.setOnClickListener(this);
    bt5.setOnClickListener(this);
    bt6.setOnClickListener(this);

    bt7.setOnClickListener(this);
    bt8.setOnClickListener(this);
    bt9.setOnClickListener(this);
}
 
Example 2
Project: GitHub   File: ReadActivity.java   View source code 6 votes vote down vote up
private void changedMode(boolean isNight, int position) {
    SharedPreferencesUtil.getInstance().putBoolean(Constant.ISNIGHT, isNight);
    AppCompatDelegate.setDefaultNightMode(isNight ? AppCompatDelegate.MODE_NIGHT_YES
            : AppCompatDelegate.MODE_NIGHT_NO);

    if (position >= 0) {
        curTheme = position;
    } else {
        curTheme = SettingManager.getInstance().getReadTheme();
    }
    gvAdapter.select(curTheme);

    mPageWidget.setTheme(isNight ? ThemeManager.NIGHT : curTheme);
    mPageWidget.setTextColor(ContextCompat.getColor(mContext, isNight ? R.color.chapter_content_night : R.color.chapter_content_day),
            ContextCompat.getColor(mContext, isNight ? R.color.chapter_title_night : R.color.chapter_title_day));

    mTvBookReadMode.setText(getString(isNight ? R.string.book_read_mode_day_manual_setting
            : R.string.book_read_mode_night_manual_setting));
    Drawable drawable = ContextCompat.getDrawable(this, isNight ? R.drawable.ic_menu_mode_day_manual
            : R.drawable.ic_menu_mode_night_manual);
    drawable.setBounds(0, 0, drawable.getMinimumWidth(), drawable.getMinimumHeight());
    mTvBookReadMode.setCompoundDrawables(null, drawable, null, null);

    ThemeManager.setReaderTheme(curTheme, mRlBookReadRoot);
}
 
Example 3
Project: AURdroid   File: MainActivity.java   View source code 6 votes vote down vote up
@Override
public boolean onPrepareOptionsMenu(Menu menu) {
    /*
      app share and rate group
      hide on AurPackageDetailsFragment
     */
    MenuItem menuItem = menu.findItem(R.id.menu_main_app_group);
    Fragment fragmentByTag = fragmentManager.findFragmentByTag(AUR_PACKAGE_DETAILS_FRAGMENT_TAG);
    menuItem.setVisible(fragmentByTag == null);
    // night mode
    switch (AppCompatDelegate.getDefaultNightMode()) {
        case AppCompatDelegate.MODE_NIGHT_AUTO:
            menu.findItem(R.id.menu_main_action_night_mode_auto).setChecked(true);
            break;
        case AppCompatDelegate.MODE_NIGHT_YES:
            menu.findItem(R.id.menu_main_action_night_mode_night).setChecked(true);
            break;
        case AppCompatDelegate.MODE_NIGHT_NO:
            menu.findItem(R.id.menu_main_action_night_mode_day).setChecked(true);
            break;
    }
    return true;
}
 
Example 4
Project: AURdroid   File: MainActivity.java   View source code 6 votes vote down vote up
@Override
protected void onCreate(Bundle savedInstanceState) {
    fragmentManager = getSupportFragmentManager();
    sharedPreferences = PreferenceManager.getDefaultSharedPreferences(this);
    int nightMode = sharedPreferences.getInt(getResources().getString(R.string.key_night_mode),
            AppCompatDelegate.MODE_NIGHT_YES);
    AppCompatDelegate.setDefaultNightMode(nightMode);
    setTheme(R.style.AppTheme_NoActionBar);
    super.onCreate(savedInstanceState);
    setContentView(R.layout.activity_main);
    Toolbar toolbar = findViewById(R.id.toolbar);
    setSupportActionBar(toolbar);
    if (findViewById(R.id.main_fragment_container) != null) {
        if (savedInstanceState != null) {
            return;
        }
        SearchFragment searchFragment = new SearchFragment();
        fragmentManager.beginTransaction()
                .add(R.id.main_fragment_container, searchFragment)
                .commit();
    }
}
 
Example 5
Project: ConnectU   File: ProfesoresActivity.java   View source code 6 votes vote down vote up
@Override
protected void onCreate(Bundle savedInstanceState) {
    super.onCreate(savedInstanceState);
    AppCompatDelegate.setCompatVectorFromResourcesEnabled(true);
    setContentView(R.layout.activity_profesores);
    //Action bar
    Toolbar toolbar = (Toolbar) findViewById(R.id.toolbar);
    setSupportActionBar(toolbar);
    getSupportActionBar().setDisplayHomeAsUpEnabled(true);
    if (Build.VERSION.SDK_INT >= 21) {
        getWindow().setNavigationBarColor(getResources().getColor(R.color.colorPrimaryDarkGreen));
        getWindow().setStatusBarColor(getResources().getColor(R.color.colorPrimaryDarkGreen));
    }
    app = (App) this.getApplication();
    year = app.getPublicPreferenceI(Common.GLOBAL_FILTER_YEAR);

    recyclerView = (RecyclerView) findViewById(R.id.profesoresRecycler);
    emptyView = (LinearLayout) findViewById(R.id.profesores_blank);
    recyclerView.setHasFixedSize(true);
    mLayoutManager = new LinearLayoutManager(getBaseContext());
    recyclerView.setLayoutManager(mLayoutManager);

    setYearAdapters();
    setSubjectsAdapter();
    updateYear(year);
}
 
Example 6
Project: PNightMode   File: BaseAppCompatActivity.java   View source code 6 votes vote down vote up
@Override
public boolean onOptionsItemSelected(MenuItem item) {
    switch (item.getItemId()) {
        case R.id.action_day:
            toggleNightModeForAllActivities(AppCompatDelegate.MODE_NIGHT_NO);
            return true;
        case R.id.action_night:
            toggleNightModeForAllActivities(AppCompatDelegate.MODE_NIGHT_YES);
            return true;
        case R.id.action_auto:
            toggleNightModeForAllActivities(AppCompatDelegate.MODE_NIGHT_AUTO);
            return true;
        default:
            return super.onOptionsItemSelected(item);
    }
}
 
Example 7
Project: MaterialLearning   File: PrefFragment.java   View source code 6 votes vote down vote up
public boolean onPreferenceChange(Preference preference, Object newValue) {
switch (preference.getKey()){
    case "pref_user_name":
        userInFo.setTitle("尊敬的"+"“"+nickname+"”");
        userInFo.setSummary("欢迎使用本应用");
        break;

    case"pref_theme_dark":
        if((boolean)newValue) {
            AppCompatDelegate.setDefaultNightMode(AppCompatDelegate.MODE_NIGHT_YES);
        } else  {
            AppCompatDelegate.setDefaultNightMode(AppCompatDelegate.MODE_NIGHT_NO);
        }
        ActivityCollector.activities.get(0).recreate();//返回栈的首节点应该是主活动,让它重启
        getActivity().recreate();

        //Toast.makeText(getActivity(), "都说了功能还在开发中"+newValue, Toast.LENGTH_SHORT).show();
        break;
}

    return true;
}
 
Example 8
Project: techstar-org   File: AboutUsActivity.java   View source code 6 votes vote down vote up
void simulateDayNight(int currentSetting) {
    final int DAY = 0;
    final int NIGHT = 1;
    final int FOLLOW_SYSTEM = 3;

    int currentNightMode = getResources().getConfiguration().uiMode
            & Configuration.UI_MODE_NIGHT_MASK;
    if (currentSetting == DAY && currentNightMode != Configuration.UI_MODE_NIGHT_NO) {
        AppCompatDelegate.setDefaultNightMode(
                AppCompatDelegate.MODE_NIGHT_NO);
    } else if (currentSetting == NIGHT && currentNightMode != Configuration.UI_MODE_NIGHT_YES) {
        AppCompatDelegate.setDefaultNightMode(
                AppCompatDelegate.MODE_NIGHT_YES);
    } else if (currentSetting == FOLLOW_SYSTEM) {
        AppCompatDelegate.setDefaultNightMode(
                AppCompatDelegate.MODE_NIGHT_FOLLOW_SYSTEM);
    }
}
 
Example 9
Project: Android-skin-support   File: App.java   View source code 6 votes vote down vote up
@Override
    public void onCreate() {
        super.onCreate();
//        SkinCircleImageViewManager.init(this);
//        SkinMaterialManager.init(this);
//        SkinConstraintManager.init(this);
//        SkinCardViewManager.init(this);
//        SkinFlycoTabLayoutManager.init(this);
//        SkinCompatManager.init(this).loadSkin();
//        SkinCompatManager.init(this)
        SkinCompatManager.withoutActivity(this)
                .addStrategy(new CustomSDCardLoader())          // 自定义加载策略,指定SDCard路径
                .addInflater(new SkinMaterialViewInflater())    // material design
                .addInflater(new SkinConstraintViewInflater())  // ConstraintLayout
                .addInflater(new SkinCardViewInflater())        // CardView v7
                .addInflater(new SkinCircleImageViewInflater()) // hdodenhof/CircleImageView
                .addInflater(new SkinFlycoTabLayoutInflater())  // H07000223/FlycoTabLayout
//                .setSkinStatusBarColorEnable(false)             // 关闭状态栏换肤
//                .setSkinWindowBackgroundEnable(false)           // 关闭windowBackground换肤
//                .setSkinAllActivityEnable(false)                // true: 默认所有的Activity都换肤; false: 只有实现SkinCompatSupportable接口的Activity换肤
                .loadSkin();
        AppCompatDelegate.setCompatVectorFromResourcesEnabled(true);
    }
 
Example 10
Project: youth-health   File: AboutUsActivity.java   View source code 6 votes vote down vote up
void simulateDayNight(int currentSetting) {
    final int DAY = 0;
    final int NIGHT = 1;
    final int FOLLOW_SYSTEM = 3;

    int currentNightMode = getResources().getConfiguration().uiMode
            & Configuration.UI_MODE_NIGHT_MASK;
    if (currentSetting == DAY && currentNightMode != Configuration.UI_MODE_NIGHT_NO) {
        AppCompatDelegate.setDefaultNightMode(
                AppCompatDelegate.MODE_NIGHT_NO);
    } else if (currentSetting == NIGHT && currentNightMode != Configuration.UI_MODE_NIGHT_YES) {
        AppCompatDelegate.setDefaultNightMode(
                AppCompatDelegate.MODE_NIGHT_YES);
    } else if (currentSetting == FOLLOW_SYSTEM) {
        AppCompatDelegate.setDefaultNightMode(
                AppCompatDelegate.MODE_NIGHT_FOLLOW_SYSTEM);
    }
}
 
Example 11
Project: KernelAdiutor-Mod   File: BaseActivity.java   View source code 6 votes vote down vote up
@Override
protected void onCreate(@Nullable Bundle savedInstanceState) {
    AppCompatDelegate.setCompatVectorFromResourcesEnabled(true);
    Utils.DARK_THEME = Prefs.getBoolean("darktheme", false, this);
    int theme;
    String accent = Prefs.getString("accent_color", "pink_accent", this);
    if (Utils.DARK_THEME) {
        theme = sAccentDarkColors.get(accent);
        AppCompatDelegate.setDefaultNightMode(AppCompatDelegate.MODE_NIGHT_YES);
    } else {
        theme = sAccentColors.get(accent);
        AppCompatDelegate.setDefaultNightMode(AppCompatDelegate.MODE_NIGHT_NO);
    }
    setTheme(theme);
    super.onCreate(savedInstanceState);
    if (Prefs.getBoolean("forceenglish", false, this)) {
        Utils.setLocale("en_US", this);
    }

    if (Build.VERSION.SDK_INT >= Build.VERSION_CODES.LOLLIPOP && setStatusBarColor()) {
        Window window = getWindow();
        window.clearFlags(WindowManager.LayoutParams.FLAG_TRANSLUCENT_STATUS);
        window.addFlags(WindowManager.LayoutParams.FLAG_DRAWS_SYSTEM_BAR_BACKGROUNDS);
        window.setStatusBarColor(statusBarColor());
    }
}
 
Example 12
Project: Movie-Notifier-Android   File: MovieNotifierApp.java   View source code 6 votes vote down vote up
@Override
public void onCreate() {
    super.onCreate();
    StethoUtil.install(this);

    AppCompatDelegate.setDefaultNightMode(getSharedPreferences("settings", MODE_PRIVATE).getInt("prefDayNight", AppCompatDelegate.MODE_NIGHT_AUTO));

    FontRequest fontRequest = new FontRequest(
            "com.google.android.gms.fonts",
            "com.google.android.gms",
            "Noto Color Emoji Compat",
            R.array.com_google_android_gms_fonts_certs);
    EmojiCompat.Config config = new FontRequestEmojiCompatConfig(this, fontRequest);
    EmojiCompat.init(config);

    setupCinemaListUpdates();
}
 
Example 13
Project: MTweaks-KernelAdiutorMOD   File: BaseActivity.java   View source code 6 votes vote down vote up
@Override
protected void onCreate(@Nullable Bundle savedInstanceState) {
    AppCompatDelegate.setCompatVectorFromResourcesEnabled(true);
    Utils.DARK_THEME = Prefs.getBoolean("darktheme", false, this);
    int theme;
    String accent = Prefs.getString("accent_color", "pink_accent", this);
    if (Utils.DARK_THEME) {
        theme = sAccentDarkColors.get(accent);
        AppCompatDelegate.setDefaultNightMode(AppCompatDelegate.MODE_NIGHT_YES);
    } else {
        theme = sAccentColors.get(accent);
        AppCompatDelegate.setDefaultNightMode(AppCompatDelegate.MODE_NIGHT_NO);
    }
    setTheme(theme);
    super.onCreate(savedInstanceState);
    if (Prefs.getBoolean("forceenglish", false, this)) {
        Utils.setLocale("en_US", this);
    }

    if (Build.VERSION.SDK_INT >= Build.VERSION_CODES.LOLLIPOP && setStatusBarColor()) {
        Window window = getWindow();
        window.clearFlags(WindowManager.LayoutParams.FLAG_TRANSLUCENT_STATUS);
        window.addFlags(WindowManager.LayoutParams.FLAG_DRAWS_SYSTEM_BAR_BACKGROUNDS);
        window.setStatusBarColor(statusBarColor());
    }
}
 
Example 14
Project: techstar-shop   File: ActivitySplashScreen.java   View source code 6 votes vote down vote up
@Override
protected void onCreate(Bundle savedInstanceState) {
    AppCompatDelegate.setCompatVectorFromResourcesEnabled(true);
    super.onCreate(savedInstanceState);
    setContentView(R.layout.activity_splash_screen);

    prefManager = new PrefManager(this);

    AppCompatImageView en = (AppCompatImageView)findViewById(R.id.langEn);
    AppCompatImageView mn = (AppCompatImageView)findViewById(R.id.langMn);
    AppCompatImageView cn = (AppCompatImageView)findViewById(R.id.langCn);
    AppCompatImageView ru = (AppCompatImageView)findViewById(R.id.langRu);

    mn.setOnClickListener(this);
    en.setOnClickListener(this);
    cn.setOnClickListener(this);
    ru.setOnClickListener(this);
}
 
Example 15
Project: Movie-Notifier-Android   File: MainActivity.java   View source code 6 votes vote down vote up
@Override
protected void onCreate(Bundle savedInstanceState) {
    super.onCreate(savedInstanceState);
    setContentView(R.layout.activity_main);
    ButterKnife.bind(this);

    setSupportActionBar(toolbar);

    dayNightPreference = getSharedPreferences("settings", MODE_PRIVATE).getInt("prefDayNight", AppCompatDelegate.MODE_NIGHT_AUTO);

    if(savedInstanceState == null) {
        getSupportFragmentManager().beginTransaction().add(R.id.frame, new WatchersFragment(), "watchersFragment").commit();
    }

    settings = getSharedPreferences("settings", MODE_PRIVATE);
}
 
Example 16
Project: javaide   File: JavaApplication.java   View source code 5 votes vote down vote up
@Override
public void onCreate() {
    super.onCreate();
    systemOut = new InterceptorOutputStream(System.out, out);
    systemErr = new InterceptorOutputStream(System.err, err);
    System.setOut(systemOut);
    System.setErr(systemErr);

    //for log cat
    AppCompatDelegate.setCompatVectorFromResourcesEnabled(true);
}
 
Example 17
Project: Android-skin-support   File: SkinCompatResources.java   View source code 5 votes vote down vote up
private Drawable getSkinDrawableCompat(Context context, int resId) {
    if (AppCompatDelegate.isCompatVectorFromResourcesEnabled()) {
        if (!isDefaultSkin) {
            try {
                return SkinCompatDrawableManager.get().getDrawable(context, resId);
            } catch (Exception e) {
                e.printStackTrace();
            }
        }
        return AppCompatResources.getDrawable(context, resId);
    } else {
        return getSkinDrawable(context, resId);
    }
}
 
Example 18
Project: ZhidaoDaily-android   File: MainActivity.java   View source code 5 votes vote down vote up
@Override
protected void onActivityResult(int requestCode, int resultCode, Intent data) {
    super.onActivityResult(requestCode, resultCode, data);
    if (requestCode == REQUEST_CODE_SETTING
            && resultCode == SettingActivity.CODE_CHANGE_SKIN) {
        getDelegate().setLocalNightMode(AppUtils.getInstance().getThemeConfig(this)
                ? AppCompatDelegate.MODE_NIGHT_YES : AppCompatDelegate.MODE_NIGHT_NO);
        recreate();
    }
}
 
Example 19
Project: Movie-Notifier-Android   File: MainActivity.java   View source code 5 votes vote down vote up
@Override
protected void onResume() {
    super.onResume();
    if(settings.getInt("prefDayNight", AppCompatDelegate.MODE_NIGHT_AUTO) != dayNightPreference) {
        recreate();
    }
}
 
Example 20
Project: GitHub   File: BaseActivity.java   View source code 5 votes vote down vote up
@Override
public void useNightMode(boolean isNight) {
    if (isNight) {
        AppCompatDelegate.setDefaultNightMode(
                AppCompatDelegate.MODE_NIGHT_YES);
    } else {
        AppCompatDelegate.setDefaultNightMode(
                AppCompatDelegate.MODE_NIGHT_NO);
    }
    recreate();
}
 
Example 21
Project: GitHub   File: App.java   View source code 5 votes vote down vote up
@Override
public void onCreate() {
    super.onCreate();

    // the 'theme' has two values, 0 and 1
    // 0 --> day theme, 1 --> night theme
    if (getSharedPreferences("user_settings",MODE_PRIVATE).getInt("theme", 0) == 0) {
        AppCompatDelegate.setDefaultNightMode(AppCompatDelegate.MODE_NIGHT_NO);
    } else {
        AppCompatDelegate.setDefaultNightMode(AppCompatDelegate.MODE_NIGHT_YES);
    }
}
 
Example 22
Project: GitHub   File: BaseActivity.java   View source code 5 votes vote down vote up
@Override
protected void onResume() {
    super.onResume();
    if (SharedPreferencesUtil.getInstance().getBoolean(Constant.ISNIGHT, false) != mNowMode) {
        if (SharedPreferencesUtil.getInstance().getBoolean(Constant.ISNIGHT, false)) {
            AppCompatDelegate.setDefaultNightMode(AppCompatDelegate.MODE_NIGHT_YES);
        } else {
            AppCompatDelegate.setDefaultNightMode(AppCompatDelegate.MODE_NIGHT_NO);
        }
        recreate();
    }
}
 
Example 23
Project: AC2RD   File: Filters.java   View source code 5 votes vote down vote up
@Override
     public void onCreate(Bundle savedInstanceState)
     {
     	localizerManager.setPreferencesLocale(getApplicationContext());
themeManager.setPreferencesTheme(getApplicationContext(), this);

delegate = AppCompatDelegate.create(this, this);
delegate.installViewFactory();

     	super.onCreate(savedInstanceState);
     	
     	delegate.onCreate(savedInstanceState);
 
      delegate.setContentView(R.layout.filters);
      
      Toolbar toolbar = (Toolbar)findViewById(R.id.filters_toolbar);
      delegate.setSupportActionBar(toolbar);
      delegate.getSupportActionBar().setLogo(R.drawable.ic_menu_friendslist);
      delegate.setTitle(getApplicationContext().getString(R.string.filters_toolbar));
      delegate.getSupportActionBar().setDisplayHomeAsUpEnabled(true);
      delegate.getSupportActionBar().setDisplayShowHomeEnabled(true);
      
      orderBy = CONTACT_FILTER.DEFAULT_SORT_ORDER;
      cursor = databaseManager.queryAllFilter(getApplicationContext(), cursor, orderBy);
      
      setCursorAdapter();
      
      listView.setOnItemClickListener(this);
listView.setOnItemLongClickListener(this);
      listView.setEmptyView(findViewById(R.id.filters_empty));
      
      Button addRecordableContact = (Button) findViewById (R.id.filters_add_recordable_contact);
      Button addNotRecordableContact = (Button) findViewById (R.id.filters_add_not_recordable_contact);
      
      addRecordableContact.setOnClickListener(this);
      addNotRecordableContact.setOnClickListener(this);
      
      recordableContact = 0;
      displayContacts = 2;
     }
 
Example 24
Project: Kids-Portal-Android   File: Activity_settings_app.java   View source code 5 votes vote down vote up
@Override
protected void onCreate(Bundle savedInstanceState) {
    super.onCreate(savedInstanceState);

    helper_main.setTheme(this);

    setContentView(R.layout.activity_settings);
    helper_main.onStart(Activity_settings_app.this);

    Toolbar toolbar = (Toolbar) findViewById(R.id.toolbar);
    setSupportActionBar(toolbar);
    setTitle(R.string.pref_2);

    AppCompatDelegate.setCompatVectorFromResourcesEnabled(true);

    android.support.v7.app.ActionBar actionBar = getSupportActionBar();
    if(actionBar != null) {
        actionBar.setDisplayHomeAsUpEnabled(true);
    }

    PreferenceManager.setDefaultValues(this, R.xml.user_settings, false);
    PreferenceManager.setDefaultValues(this, R.xml.user_settings_search, false);
    PreferenceManager.setDefaultValues(this, R.xml.user_settings_app, false);
    PreferenceManager.setDefaultValues(this, R.xml.user_settings_close, false);
    PreferenceManager.setDefaultValues(this, R.xml.user_settings_start, false);
    PreferenceManager.setDefaultValues(this, R.xml.user_settings_search_main, false);
    PreferenceManager.setDefaultValues(this, R.xml.user_settings_data, false);
    SharedPreferences sharedPref = PreferenceManager.getDefaultSharedPreferences(this);
    sharedPref.edit().putString("started", "").apply();

    // Display the fragment as the activity_screen_main content
    getFragmentManager().beginTransaction().replace(R.id.content_frame, new SettingsFragment()).commit();
}
 
Example 25
Project: ConnectU   File: ExpedienteActivity.java   View source code 5 votes vote down vote up
@Override
protected void onCreate(Bundle savedInstanceState) {
    super.onCreate(savedInstanceState);
    AppCompatDelegate.setCompatVectorFromResourcesEnabled(true);
    setContentView(R.layout.activity_expediente);
    //Action bar
    Toolbar toolbar = (Toolbar) findViewById(R.id.toolbar);
    setSupportActionBar(toolbar);
    getSupportActionBar().setDisplayHomeAsUpEnabled(true);
    if (Build.VERSION.SDK_INT >= 21) {
        getWindow().setNavigationBarColor(getResources().getColor(R.color.colorPrimaryDarkGreen));
        getWindow().setStatusBarColor(getResources().getColor(R.color.colorPrimaryDarkGreen));
    }
}
 
Example 26
Project: ConnectU   File: ProfilePreference.java   View source code 5 votes vote down vote up
@Override
public void onBindViewHolder(PreferenceViewHolder holder) {
    super.onBindViewHolder(holder);
    AppCompatDelegate.setCompatVectorFromResourcesEnabled(true);
    App app = (App) getContext().getApplicationContext();
    TextView user = (TextView) holder.findViewById(R.id.user_Name);
    ImageView picture = (ImageView) holder.findViewById(R.id.user_Profile);
    String name = app.account.getName();
    if (name == null) {
        name = "User";
    }
    user.setText(name);
    Picasso.with(getContext()).load(app.account.getPictureURL()).placeholder(R.drawable.ic_placeholder).into(picture);
}
 
Example 27
Project: Kids-Portal-Android   File: Activity_settings_close.java   View source code 5 votes vote down vote up
@Override
protected void onCreate(Bundle savedInstanceState) {
    super.onCreate(savedInstanceState);

    helper_main.setTheme(this);

    setContentView(R.layout.activity_settings);
    helper_main.onStart(Activity_settings_close.this);

    Toolbar toolbar = (Toolbar) findViewById(R.id.toolbar);
    setSupportActionBar(toolbar);
    setTitle(R.string.pref_5);

    AppCompatDelegate.setCompatVectorFromResourcesEnabled(true);

    android.support.v7.app.ActionBar actionBar = getSupportActionBar();
    if(actionBar != null) {
        actionBar.setDisplayHomeAsUpEnabled(true);
    }

    PreferenceManager.setDefaultValues(this, R.xml.user_settings, false);
    PreferenceManager.setDefaultValues(this, R.xml.user_settings_search, false);
    PreferenceManager.setDefaultValues(this, R.xml.user_settings_app, false);
    PreferenceManager.setDefaultValues(this, R.xml.user_settings_close, false);
    PreferenceManager.setDefaultValues(this, R.xml.user_settings_start, false);
    PreferenceManager.setDefaultValues(this, R.xml.user_settings_search_main, false);
    PreferenceManager.setDefaultValues(this, R.xml.user_settings_data, false);
    SharedPreferences sharedPref = PreferenceManager.getDefaultSharedPreferences(this);
    sharedPref.edit().putString("started", "").apply();

    // Display the fragment as the activity_screen_main content
    getFragmentManager().beginTransaction().replace(R.id.content_frame, new SettingsFragment()).commit();
}
 
Example 28
Project: android-customtabs   File: Application.java   View source code 5 votes vote down vote up
@Override
public void onCreate() {
    super.onCreate();

    // Support vector drawable support for pre-Lollipop devices
    AppCompatDelegate.setCompatVectorFromResourcesEnabled(true);

    // Preload custom tabs service for improved performance
    // This is optional but recommended
    registerActivityLifecycleCallbacks(new CustomTabsActivityLifecycleCallbacks());
}
 
Example 29
Project: MaterialLearning   File: MyApplication.java   View source code 5 votes vote down vote up
@Override
public void onCreate() {
    super.onCreate();
    context = getApplicationContext();

    preferences = PreferenceManager.getDefaultSharedPreferences(context);
    boolean isNightMode=preferences.getBoolean("pref_theme_dark",false);
    if(isNightMode){
        AppCompatDelegate.setDefaultNightMode(AppCompatDelegate.MODE_NIGHT_YES);
    }
    LitePal.initialize(context);
}
 
Example 30
Project: FriendBook   File: BaseActivity.java   View source code 5 votes vote down vote up
private void initTheme() {
    //设置该app的主题根据时间不同显示
    if (AppConfig.isNightMode()) {
        AppCompatDelegate.setDefaultNightMode(AppCompatDelegate.MODE_NIGHT_YES);
    } else {
        AppCompatDelegate.setDefaultNightMode(AppCompatDelegate.MODE_NIGHT_NO);
    }

}
 
Example 31
Project: TextReader   File: BaseActivity.java   View source code 5 votes vote down vote up
@Override
protected void onResume() {
    super.onResume();
    if (SharedPreferencesUtil.getInstance().getBoolean(Constant.ISNIGHT, false) != mNowMode) {
        if (SharedPreferencesUtil.getInstance().getBoolean(Constant.ISNIGHT, false)) {
            AppCompatDelegate.setDefaultNightMode(AppCompatDelegate.MODE_NIGHT_YES);
        } else {
            AppCompatDelegate.setDefaultNightMode(AppCompatDelegate.MODE_NIGHT_NO);
        }
        recreate();
    }
}
 
Example 32
Project: stynico   File: SplashActivity.java   View source code 5 votes vote down vote up
@Override
protected void onCreate(Bundle savedInstanceState) {
    super.onCreate(savedInstanceState);
    //setContentView(R.layout.s_splash);
    boolean isFirstRun = (boolean) nico.SPUtils.get(this, "if_c_1", false);
    if (isFirstRun) {
        // AppCompatDelegate.setDefaultNightMode(AppCompatDelegate.MODE_NIGHT_YES);
    } else {
        AppCompatDelegate.setDefaultNightMode(AppCompatDelegate.MODE_NIGHT_NO);
    }
    SharedPreferences setting = SplashActivity.this.getSharedPreferences("play_", 0);
    Boolean user_first = setting.getBoolean("FIRST", true);
    if (user_first) {
        //MediaPlayer mPlayer = MediaPlayer.create(SplashActivity.this, R.raw.bio);
        //mPlayer.start();
        //Toast.makeText(SplashActivity.this, "夜间模式", Toast.LENGTH_SHORT).show();
        setting.edit().putBoolean("FIRST", false).commit();

    } else {
        boolean sFirstRun = (boolean) nico.SPUtils.get(this, "if_styTool", false);
        if (sFirstRun) {
            MediaPlayer mPlayer = MediaPlayer.create(SplashActivity.this, R.raw.bio);
            mPlayer.start();
        } else {
        }
    }

    new Handler().postDelayed(new Runnable() {
        @Override
        public void run() {
            Intent intent = new Intent(SplashActivity.this, nico.SimpleActivity.class);
            startActivity(intent);
            finish();
        }
    }, 1000L);
}
 
Example 33
Project: Kids-Portal-Android   File: Activity_settings.java   View source code 5 votes vote down vote up
@Override
protected void onCreate(Bundle savedInstanceState) {
    super.onCreate(savedInstanceState);

    helper_main.setTheme(this);

    setContentView(R.layout.activity_settings);
    helper_main.onStart(Activity_settings.this);

    Toolbar toolbar = (Toolbar) findViewById(R.id.toolbar);
    setSupportActionBar(toolbar);
    setTitle(R.string.menu_settings);

    AppCompatDelegate.setCompatVectorFromResourcesEnabled(true);

    android.support.v7.app.ActionBar actionBar = getSupportActionBar();
    if(actionBar != null) {
        actionBar.setDisplayHomeAsUpEnabled(true);
    }

    PreferenceManager.setDefaultValues(this, R.xml.user_settings, false);
    PreferenceManager.setDefaultValues(this, R.xml.user_settings_search, false);
    PreferenceManager.setDefaultValues(this, R.xml.user_settings_app, false);
    PreferenceManager.setDefaultValues(this, R.xml.user_settings_close, false);
    PreferenceManager.setDefaultValues(this, R.xml.user_settings_start, false);
    PreferenceManager.setDefaultValues(this, R.xml.user_settings_search_main, false);
    PreferenceManager.setDefaultValues(this, R.xml.user_settings_data, false);
    sharedPref = PreferenceManager.getDefaultSharedPreferences(this);
    sharedPref.edit().putString("started", "").apply();


    // Display the fragment as the activity_screen_main content
    getFragmentManager().beginTransaction().replace(R.id.content_frame, new SettingsFragment()).commit();

}
 
Example 34
Project: DuckDuckDefine-Android   File: DuckDuckDefineApplication.java   View source code 5 votes vote down vote up
@Override
public void onCreate() {
    super.onCreate();

    initialiseDependencyInjection();

    if (BuildConfig.DEBUG) {
        initTimberDebugPlant();
    }

    AppCompatDelegate.setCompatVectorFromResourcesEnabled(true);
}
 
Example 35
Project: Kids-Portal-Android   File: Activity_settings_searchMain.java   View source code 5 votes vote down vote up
@Override
protected void onCreate(Bundle savedInstanceState) {
    super.onCreate(savedInstanceState);

    helper_main.setTheme(this);

    setContentView(R.layout.activity_settings);
    helper_main.onStart(Activity_settings_searchMain.this);

    Toolbar toolbar = (Toolbar) findViewById(R.id.toolbar);
    setSupportActionBar(toolbar);
    setTitle(R.string.pref_6);

    AppCompatDelegate.setCompatVectorFromResourcesEnabled(true);

    android.support.v7.app.ActionBar actionBar = getSupportActionBar();
    if(actionBar != null) {
        actionBar.setDisplayHomeAsUpEnabled(true);
    }

    PreferenceManager.setDefaultValues(this, R.xml.user_settings, false);
    PreferenceManager.setDefaultValues(this, R.xml.user_settings_search, false);
    PreferenceManager.setDefaultValues(this, R.xml.user_settings_app, false);
    PreferenceManager.setDefaultValues(this, R.xml.user_settings_close, false);
    PreferenceManager.setDefaultValues(this, R.xml.user_settings_start, false);
    PreferenceManager.setDefaultValues(this, R.xml.user_settings_search_main, false);
    PreferenceManager.setDefaultValues(this, R.xml.user_settings_data, false);
    SharedPreferences sharedPref = PreferenceManager.getDefaultSharedPreferences(this);
    sharedPref.edit().putString("started", "").apply();

    // Display the fragment as the activity_screen_main content
    getFragmentManager().beginTransaction().replace(R.id.content_frame, new SettingsFragment()).commit();
}
 
Example 36
Project: PNightMode   File: MainAppCompatActivity.java   View source code 5 votes vote down vote up
@Override
public void onClick(View view) {
    switch (view.getId()) {
        case R.id.btn_second_activity:
            Intent intent = new Intent();
            intent.setClass(this, SecondAppCompatActivity.class);
            startActivity(intent);
            break;
        case R.id.btn_toggle_night_mode:
            int mode = AppCompatDelegate.getDefaultNightMode() == AppCompatDelegate.MODE_NIGHT_YES
                    ? AppCompatDelegate.MODE_NIGHT_NO : AppCompatDelegate.MODE_NIGHT_YES;
            toggleGlobalNightMode(mode);
            break;
    }
}
 
Example 37
Project: PNightMode   File: BaseAppCompatActivity.java   View source code 5 votes vote down vote up
public void toggleNightModeForAllActivities(@AppCompatDelegate.NightMode int mode) {
    List<BaseAppCompatActivity> list = NightModeActivityManager.getInstance().getActivityList();
    if (list != null && list.size() > 0) {
        for (BaseAppCompatActivity activity : list) {
            activity.toggleGlobalNightMode(mode);
        }
    }
}
 
Example 38
Project: Kids-Portal-Android   File: Activity_settings_data.java   View source code 5 votes vote down vote up
@Override
protected void onCreate(Bundle savedInstanceState) {
    super.onCreate(savedInstanceState);

    helper_main.setTheme(this);

    setContentView(R.layout.activity_settings);
    helper_main.onStart(Activity_settings_data.this);

    Toolbar toolbar = (Toolbar) findViewById(R.id.toolbar);
    setSupportActionBar(toolbar);
    setTitle(R.string.pref_4);

    AppCompatDelegate.setCompatVectorFromResourcesEnabled(true);

    android.support.v7.app.ActionBar actionBar = getSupportActionBar();
    if(actionBar != null) {
        actionBar.setDisplayHomeAsUpEnabled(true);
    }

    PreferenceManager.setDefaultValues(this, R.xml.user_settings, false);
    PreferenceManager.setDefaultValues(this, R.xml.user_settings_search, false);
    PreferenceManager.setDefaultValues(this, R.xml.user_settings_app, false);
    PreferenceManager.setDefaultValues(this, R.xml.user_settings_close, false);
    PreferenceManager.setDefaultValues(this, R.xml.user_settings_start, false);
    PreferenceManager.setDefaultValues(this, R.xml.user_settings_search_main, false);
    PreferenceManager.setDefaultValues(this, R.xml.user_settings_data, false);
    SharedPreferences sharedPref = PreferenceManager.getDefaultSharedPreferences(this);
    sharedPref.edit().putString("started", "").apply();

    // Display the fragment as the activity_screen_main content
    getFragmentManager().beginTransaction().replace(R.id.content_frame, new SettingsFragment()).commit();
}
 
Example 39
Project: BilibiliClient   File: MainActivity.java   View source code 5 votes vote down vote up
private void switchNightMode() {
    boolean flag = PreferenceUtil.getBoolean(ConstantUtil.SWITCH_MODE_KEY, false);
    if (flag){
        AppCompatDelegate.setDefaultNightMode(AppCompatDelegate.MODE_NIGHT_NO);
        PreferenceUtil.putBoolean(ConstantUtil.SWITCH_MODE_KEY, false);
    } else {
        AppCompatDelegate.setDefaultNightMode(AppCompatDelegate.MODE_NIGHT_YES);
        PreferenceUtil.putBoolean(ConstantUtil.SWITCH_MODE_KEY, true);
    }
    recreate();
}
 
Example 40
Project: AnotherRSS   File: MainActivity.java   View source code 5 votes vote down vote up
@Override
protected void onResume() {
    Log.d(AnotherRSS.TAG, "onResume");
    AnotherRSS.withGui = true;
    new DbExpunge().execute();

    SharedPreferences mPreferences = PreferenceManager.getDefaultSharedPreferences(getApplicationContext());
    boolean night = mPreferences.getBoolean("nightmode_use", false);
    if (night) {
        int startH = mPreferences.getInt("nightmode_use_start", AnotherRSS.Config.DEFAULT_NIGHT_START);
        int stopH = mPreferences.getInt("nightmode_use_stop", AnotherRSS.Config.DEFAULT_NIGHT_STOP);
        if (AnotherRSS.inTimeSpan(startH, stopH) && umm.getNightMode() != UiModeManager.MODE_NIGHT_YES) {
            umm.setNightMode(UiModeManager.MODE_NIGHT_YES);
            AppCompatDelegate.setDefaultNightMode(AppCompatDelegate.MODE_NIGHT_YES);
        }
        if (!AnotherRSS.inTimeSpan(startH, stopH) && umm.getNightMode() != UiModeManager.MODE_NIGHT_NO) {
            umm.setNightMode(UiModeManager.MODE_NIGHT_NO);
            AppCompatDelegate.setDefaultNightMode(AppCompatDelegate.MODE_NIGHT_NO);
        }
    } else {
        if (umm.getNightMode() == UiModeManager.MODE_NIGHT_YES) {
            umm.setNightMode(UiModeManager.MODE_NIGHT_NO);
            AppCompatDelegate.setDefaultNightMode(AppCompatDelegate.MODE_NIGHT_NO);
        }
    }
    super.onResume();
}