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 com.example.android.supportv7.R;
     19 
     20 import android.app.Dialog;
     21 import android.content.Context;
     22 import android.os.Bundle;
     23 import android.support.annotation.Nullable;
     24 import android.support.v4.view.WindowCompat;
     25 import android.support.v7.app.AppCompatActivity;
     26 import android.support.v7.app.AppCompatDelegate;
     27 import android.support.v7.app.AppCompatDialog;
     28 import android.view.Menu;
     29 import android.view.MenuItem;
     30 import android.view.View;
     31 import android.widget.Spinner;
     32 import android.widget.Toast;
     33 
     34 /**
     35  * This demonstrates idiomatic usage of Dialog with Theme.AppCompat.DayNight
     36  */
     37 public class AppCompatNightModeDialog extends AppCompatActivity {
     38 
     39     @Override
     40     protected void onCreate(@Nullable Bundle savedInstanceState) {
     41         super.onCreate(savedInstanceState);
     42         setContentView(R.layout.appcompat_night_mode);
     43     }
     44 
     45     public void setModeNightNo(View view) {
     46         AppCompatDialog dialog = new AppCompatDialog(this, R.style.Theme_AppCompat_DayNight_Dialog);
     47         dialog.getDelegate().setLocalNightMode(AppCompatDelegate.MODE_NIGHT_NO);
     48         dialog.setTitle(R.string.dialog_title);
     49         dialog.setContentView(R.layout.dialog_content);
     50         dialog.show();
     51     }
     52 
     53     public void setModeNightYes(View view) {
     54         AppCompatDialog dialog = new AppCompatDialog(this, R.style.Theme_AppCompat_DayNight_Dialog);
     55         dialog.getDelegate().setLocalNightMode(AppCompatDelegate.MODE_NIGHT_YES);
     56         dialog.setTitle(R.string.dialog_title);
     57         dialog.setContentView(R.layout.dialog_content);
     58         dialog.show();
     59     }
     60 
     61     public void setModeNightAuto(View view) {
     62         AppCompatDialog dialog = new AppCompatDialog(this, R.style.Theme_AppCompat_DayNight_Dialog);
     63         dialog.getDelegate().setLocalNightMode(AppCompatDelegate.MODE_NIGHT_AUTO);
     64         dialog.setTitle(R.string.dialog_title);
     65         dialog.setContentView(R.layout.dialog_content);
     66         dialog.show();
     67     }
     68 
     69 
     70 }
     71