Merge "Demo showing Theme.AppCompat.DayNight usage" into mnc-ub-dev

am: 7a42332712

* commit '7a4233271228b720909ba59201ae1c1e27a10357':
  Demo showing Theme.AppCompat.DayNight usage
This commit is contained in:
Chris Banes
2015-12-15 16:03:12 +00:00
committed by android-build-merger
6 changed files with 271 additions and 0 deletions

View File

@@ -31,6 +31,9 @@
reading images from the media store from API v19+. -->
<uses-permission android:name="android.permission.READ_EXTERNAL_STORAGE" />
<!-- Permission for ACCESS_COARSE_LOCATION is required for DayNight themes. -->
<uses-permission android:name="android.permission.ACCESS_COARSE_LOCATION" />
<uses-sdk android:minSdkVersion="7" android:targetSdkVersion="21" />
<!-- The smallest screen this app works on is a phone. The app will
@@ -318,6 +321,33 @@
</intent-filter>
</activity>
<activity android:name=".app.AppCompatNightModeActivity"
android:label="@string/mode_night_activity_title"
android:theme="@style/Theme.AppCompat.DayNight">
<intent-filter>
<action android:name="android.intent.action.MAIN" />
<category android:name="com.example.android.supportv7.SAMPLE_CODE" />
</intent-filter>
</activity>
<activity android:name=".app.AppCompatNightModeDialog"
android:label="@string/mode_night_dialog_title"
android:theme="@style/Theme.AppCompat">
<intent-filter>
<action android:name="android.intent.action.MAIN" />
<category android:name="com.example.android.supportv7.SAMPLE_CODE" />
</intent-filter>
</activity>
<activity android:name=".app.AppCompatNightModeAlertDialog"
android:label="@string/mode_night_alertdialog_title"
android:theme="@style/Theme.AppCompat">
<intent-filter>
<action android:name="android.intent.action.MAIN" />
<category android:name="com.example.android.supportv7.SAMPLE_CODE" />
</intent-filter>
</activity>
<provider android:name=".app.RecentSuggestionsProvider"
android:authorities="com.example.android.supportv7.RecentSuggestionsProvider" />

View File

@@ -0,0 +1,45 @@
<?xml version="1.0" encoding="utf-8"?>
<!--
Copyright (C) 2015 The Android Open Source Project
Licensed under the Apache License, Version 2.0 (the "License");
you may not use this file except in compliance with the License.
You may obtain a copy of the License at
http://www.apache.org/licenses/LICENSE-2.0
Unless required by applicable law or agreed to in writing, software
distributed under the License is distributed on an "AS IS" BASIS,
WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
See the License for the specific language governing permissions and
limitations under the License.
-->
<ScrollView xmlns:android="http://schemas.android.com/apk/res/android"
android:layout_width="match_parent"
android:layout_height="match_parent">
<LinearLayout xmlns:android="http://schemas.android.com/apk/res/android"
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:orientation="vertical"
android:padding="16dp">
<Button android:layout_width="match_parent"
android:layout_height="wrap_content"
android:text="@string/mode_night_no"
android:onClick="setModeNightNo"/>
<Button android:layout_width="match_parent"
android:layout_height="wrap_content"
android:text="@string/mode_night_yes"
android:onClick="setModeNightYes"/>
<Button android:layout_width="match_parent"
android:layout_height="wrap_content"
android:text="@string/mode_night_auto"
android:onClick="setModeNightAuto"/>
</LinearLayout>
</ScrollView>

View File

@@ -188,4 +188,12 @@
<string name="drawer_title">Navigation</string>
<string name="drawer_open">Open navigation drawer</string>
<string name="drawer_close">Close navigation drawer</string>
<string name="mode_night_yes">MODE_NIGHT_YES</string>
<string name="mode_night_no">MODE_NIGHT_NO</string>
<string name="mode_night_auto">MODE_NIGHT_AUTO</string>
<string name="mode_night_activity_title">AppCompat/DayNight/Activity Usage</string>
<string name="mode_night_dialog_title">AppCompat/DayNight/Dialog Usage</string>
<string name="mode_night_alertdialog_title">AppCompat/DayNight/AlertDialog Usage</string>
</resources>

View File

@@ -0,0 +1,53 @@
/*
* Copyright (C) 2015 The Android Open Source Project
*
* Licensed under the Apache License, Version 2.0 (the "License");
* you may not use this file except in compliance with the License.
* You may obtain a copy of the License at
*
* http://www.apache.org/licenses/LICENSE-2.0
*
* Unless required by applicable law or agreed to in writing, software
* distributed under the License is distributed on an "AS IS" BASIS,
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
* See the License for the specific language governing permissions and
* limitations under the License.
*/
package com.example.android.supportv7.app;
import com.example.android.supportv7.R;
import android.os.Bundle;
import android.support.annotation.Nullable;
import android.support.v7.app.AppCompatActivity;
import android.support.v7.app.AppCompatDelegate;
import android.view.View;
/**
* This demonstrates idiomatic usage of AppCompatActivity with Theme.AppCompat.DayNight
*/
public class AppCompatNightModeActivity extends AppCompatActivity {
@Override
protected void onCreate(@Nullable Bundle savedInstanceState) {
super.onCreate(savedInstanceState);
setContentView(R.layout.appcompat_night_mode);
}
public void setModeNightNo(View view) {
getDelegate().setLocalNightMode(AppCompatDelegate.MODE_NIGHT_NO);
recreate();
}
public void setModeNightYes(View view) {
getDelegate().setLocalNightMode(AppCompatDelegate.MODE_NIGHT_YES);
recreate();
}
public void setModeNightAuto(View view) {
getDelegate().setLocalNightMode(AppCompatDelegate.MODE_NIGHT_AUTO);
recreate();
}
}

View File

@@ -0,0 +1,65 @@
/*
* Copyright (C) 2014 The Android Open Source Project
*
* Licensed under the Apache License, Version 2.0 (the "License");
* you may not use this file except in compliance with the License.
* You may obtain a copy of the License at
*
* http://www.apache.org/licenses/LICENSE-2.0
*
* Unless required by applicable law or agreed to in writing, software
* distributed under the License is distributed on an "AS IS" BASIS,
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
* See the License for the specific language governing permissions and
* limitations under the License.
*/
package com.example.android.supportv7.app;
import com.example.android.supportv7.R;
import android.os.Bundle;
import android.support.annotation.Nullable;
import android.support.v7.app.AlertDialog;
import android.support.v7.app.AppCompatActivity;
import android.support.v7.app.AppCompatDelegate;
import android.support.v7.app.AppCompatDialog;
import android.view.View;
/**
* This demonstrates idiomatic usage of AlertDialog with Theme.AppCompat.DayNight
*/
public class AppCompatNightModeAlertDialog extends AppCompatActivity {
@Override
protected void onCreate(@Nullable Bundle savedInstanceState) {
super.onCreate(savedInstanceState);
setContentView(R.layout.appcompat_night_mode);
}
public void setModeNightNo(View view) {
AlertDialog dialog = createAlertDialog();
dialog.getDelegate().setLocalNightMode(AppCompatDelegate.MODE_NIGHT_NO);
dialog.show();
}
public void setModeNightYes(View view) {
AlertDialog dialog = createAlertDialog();
dialog.getDelegate().setLocalNightMode(AppCompatDelegate.MODE_NIGHT_YES);
dialog.show();
}
public void setModeNightAuto(View view) {
AlertDialog dialog = createAlertDialog();
dialog.getDelegate().setLocalNightMode(AppCompatDelegate.MODE_NIGHT_AUTO);
dialog.show();
}
private AlertDialog createAlertDialog() {
AlertDialog.Builder b = new AlertDialog.Builder(this,
R.style.Theme_AppCompat_DayNight_Dialog_Alert);
b.setTitle(R.string.dialog_title);
b.setMessage(R.string.dialog_content);
return b.create();
}
}

View File

@@ -0,0 +1,70 @@
/*
* Copyright (C) 2014 The Android Open Source Project
*
* Licensed under the Apache License, Version 2.0 (the "License");
* you may not use this file except in compliance with the License.
* You may obtain a copy of the License at
*
* http://www.apache.org/licenses/LICENSE-2.0
*
* Unless required by applicable law or agreed to in writing, software
* distributed under the License is distributed on an "AS IS" BASIS,
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
* See the License for the specific language governing permissions and
* limitations under the License.
*/
package com.example.android.supportv7.app;
import com.example.android.supportv7.R;
import android.app.Dialog;
import android.content.Context;
import android.os.Bundle;
import android.support.annotation.Nullable;
import android.support.v4.view.WindowCompat;
import android.support.v7.app.AppCompatActivity;
import android.support.v7.app.AppCompatDelegate;
import android.support.v7.app.AppCompatDialog;
import android.view.Menu;
import android.view.MenuItem;
import android.view.View;
import android.widget.Spinner;
import android.widget.Toast;
/**
* This demonstrates idiomatic usage of Dialog with Theme.AppCompat.DayNight
*/
public class AppCompatNightModeDialog extends AppCompatActivity {
@Override
protected void onCreate(@Nullable Bundle savedInstanceState) {
super.onCreate(savedInstanceState);
setContentView(R.layout.appcompat_night_mode);
}
public void setModeNightNo(View view) {
AppCompatDialog dialog = new AppCompatDialog(this, R.style.Theme_AppCompat_DayNight_Dialog);
dialog.getDelegate().setLocalNightMode(AppCompatDelegate.MODE_NIGHT_NO);
dialog.setTitle(R.string.dialog_title);
dialog.setContentView(R.layout.dialog_content);
dialog.show();
}
public void setModeNightYes(View view) {
AppCompatDialog dialog = new AppCompatDialog(this, R.style.Theme_AppCompat_DayNight_Dialog);
dialog.getDelegate().setLocalNightMode(AppCompatDelegate.MODE_NIGHT_YES);
dialog.setTitle(R.string.dialog_title);
dialog.setContentView(R.layout.dialog_content);
dialog.show();
}
public void setModeNightAuto(View view) {
AppCompatDialog dialog = new AppCompatDialog(this, R.style.Theme_AppCompat_DayNight_Dialog);
dialog.getDelegate().setLocalNightMode(AppCompatDelegate.MODE_NIGHT_AUTO);
dialog.setTitle(R.string.dialog_title);
dialog.setContentView(R.layout.dialog_content);
dialog.show();
}
}