Home | History | Annotate | Download | only in app
      1 /*
      2  * Copyright (C) 2014 The Android Open Source Project
      3  *
      4  * Licensed under the Apache License, Version 2.0 (the "License");
      5  * you may not use this file except in compliance with the License.
      6  * You may obtain a copy of the License at
      7  *
      8  *      http://www.apache.org/licenses/LICENSE-2.0
      9  *
     10  * Unless required by applicable law or agreed to in writing, software
     11  * distributed under the License is distributed on an "AS IS" BASIS,
     12  * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
     13  * See the License for the specific language governing permissions and
     14  * limitations under the License.
     15  */
     16 package com.example.android.supportv7.app;
     17 
     18 import android.os.Bundle;
     19 import android.view.View;
     20 
     21 import androidx.annotation.Nullable;
     22 import androidx.appcompat.app.AlertDialog;
     23 import androidx.appcompat.app.AppCompatActivity;
     24 import androidx.appcompat.app.AppCompatDelegate;
     25 
     26 import com.example.android.supportv7.R;
     27 
     28 /**
     29  * This demonstrates idiomatic usage of AlertDialog with Theme.AppCompat.DayNight
     30  */
     31 public class AppCompatNightModeAlertDialog extends AppCompatActivity {
     32 
     33     @Override
     34     protected void onCreate(@Nullable Bundle savedInstanceState) {
     35         super.onCreate(savedInstanceState);
     36         setContentView(R.layout.appcompat_night_mode);
     37     }
     38 
     39     public void setModeNightNo(View view) {
     40         AlertDialog dialog = createAlertDialog();
     41         dialog.getDelegate().setLocalNightMode(AppCompatDelegate.MODE_NIGHT_NO);
     42         dialog.show();
     43     }
     44 
     45     public void setModeNightYes(View view) {
     46         AlertDialog dialog = createAlertDialog();
     47         dialog.getDelegate().setLocalNightMode(AppCompatDelegate.MODE_NIGHT_YES);
     48         dialog.show();
     49     }
     50 
     51     public void setModeNightAuto(View view) {
     52         AlertDialog dialog = createAlertDialog();
     53         dialog.getDelegate().setLocalNightMode(AppCompatDelegate.MODE_NIGHT_AUTO);
     54         dialog.show();
     55     }
     56 
     57     private AlertDialog createAlertDialog() {
     58         AlertDialog.Builder b = new AlertDialog.Builder(this,
     59                 R.style.Theme_AppCompat_DayNight_Dialog_Alert);
     60         b.setTitle(R.string.dialog_title);
     61         b.setMessage(R.string.dialog_content);
     62         return b.create();
     63     }
     64 
     65 }
     66