Skip to content

Commit

Permalink
Merge pull request #31 from cemrich/app-compat
Browse files Browse the repository at this point in the history
Use AppCompat components wherever possible
  • Loading branch information
arnowelzel authored Apr 1, 2017
2 parents e49f12c + aaf310b commit 324d868
Show file tree
Hide file tree
Showing 12 changed files with 188 additions and 80 deletions.
5 changes: 3 additions & 2 deletions app/build.gradle
Original file line number Diff line number Diff line change
Expand Up @@ -31,6 +31,7 @@ android {
}

dependencies {
compile 'com.android.support:support-v4:25.1.0'
compile 'com.android.support:support-annotations:25.1.0'
compile 'com.android.support:appcompat-v7:25.3.0'
compile 'com.android.support:support-v4:25.3.0'
compile 'com.android.support:support-annotations:25.3.0'
}
5 changes: 3 additions & 2 deletions app/src/main/AndroidManifest.xml
Original file line number Diff line number Diff line change
Expand Up @@ -9,8 +9,9 @@
android:label="@string/app_name"
android:icon="@drawable/periodical"
android:allowBackup="true"
android:fullBackupContent="true">

android:fullBackupContent="true"
android:theme="@style/Theme.AppCompat">

<activity android:name=".MainActivity" android:label="@string/app_name"
android:icon="@drawable/periodical">
<intent-filter>
Expand Down
Original file line number Diff line number Diff line change
@@ -0,0 +1,108 @@
/*
* 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 android.content.res.Configuration;
import android.os.Bundle;
import android.preference.PreferenceActivity;
import android.support.annotation.LayoutRes;
import android.support.annotation.Nullable;
import android.support.v7.app.ActionBar;
import android.support.v7.app.AppCompatDelegate;
import android.support.v7.widget.Toolbar;
import android.view.MenuInflater;
import android.view.View;
import android.view.ViewGroup;
/**
* A {@link android.preference.PreferenceActivity} which implements and proxies the necessary calls
* to be used with AppCompat.
*
* This technique can be used with an {@link android.app.Activity} class, not just
* {@link android.preference.PreferenceActivity}.
*/
public abstract class AppCompatPreferenceActivity extends PreferenceActivity {
private AppCompatDelegate mDelegate;
@Override
protected void onCreate(Bundle savedInstanceState) {
getDelegate().installViewFactory();
getDelegate().onCreate(savedInstanceState);
super.onCreate(savedInstanceState);
}
@Override
protected void onPostCreate(Bundle savedInstanceState) {
super.onPostCreate(savedInstanceState);
getDelegate().onPostCreate(savedInstanceState);
}
public ActionBar getSupportActionBar() {
return getDelegate().getSupportActionBar();
}
public void setSupportActionBar(@Nullable Toolbar toolbar) {
getDelegate().setSupportActionBar(toolbar);
}
@Override
public MenuInflater getMenuInflater() {
return getDelegate().getMenuInflater();
}
@Override
public void setContentView(@LayoutRes int layoutResID) {
getDelegate().setContentView(layoutResID);
}
@Override
public void setContentView(View view) {
getDelegate().setContentView(view);
}
@Override
public void setContentView(View view, ViewGroup.LayoutParams params) {
getDelegate().setContentView(view, params);
}
@Override
public void addContentView(View view, ViewGroup.LayoutParams params) {
getDelegate().addContentView(view, params);
}
@Override
protected void onPostResume() {
super.onPostResume();
getDelegate().onPostResume();
}
@Override
protected void onTitleChanged(CharSequence title, int color) {
super.onTitleChanged(title, color);
getDelegate().setTitle(title);
}
@Override
public void onConfigurationChanged(Configuration newConfig) {
super.onConfigurationChanged(newConfig);
getDelegate().onConfigurationChanged(newConfig);
}
@Override
protected void onStop() {
super.onStop();
getDelegate().onStop();
}
@Override
protected void onDestroy() {
super.onDestroy();
getDelegate().onDestroy();
}
public void invalidateOptionsMenu() {
getDelegate().invalidateOptionsMenu();
}
private AppCompatDelegate getDelegate() {
if (mDelegate == null) {
mDelegate = AppCompatDelegate.create(this, null);
}
return mDelegate;
}
}
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
/**
* Periodical "about" activity
* Periodical "about" activity
* Copyright (C) 2012-2015 Arno Welzel
*
* This code is free software: you can redistribute it and/or modify
Expand All @@ -19,17 +19,17 @@
package de.arnowelzel.android.periodical;

import android.annotation.SuppressLint;
import android.app.ActionBar;
import android.app.Activity;
import android.os.Bundle;
import android.support.v7.app.ActionBar;
import android.support.v7.app.AppCompatActivity;
import android.view.MenuItem;
import android.webkit.WebView;
import android.webkit.WebViewClient;

/**
* Activity to handle the "About" command
*/
public class AboutActivity extends Activity {
public class AboutActivity extends AppCompatActivity {

/**
* Called when the activity starts
Expand All @@ -55,13 +55,11 @@ public void onPageFinished(WebView view, String url) {
view.loadUrl("file:///android_asset/"+getString(R.string.asset_about));

// Activate "back button" in Action Bar if possible
if (android.os.Build.VERSION.SDK_INT >= 11) {
ActionBar actionBar = getActionBar();
assert actionBar != null;
actionBar.setDisplayHomeAsUpEnabled(true);
}
ActionBar actionBar = getSupportActionBar();
assert actionBar != null;
actionBar.setDisplayHomeAsUpEnabled(true);
}

/**
* Handler for ICS "home" button
*/
Expand All @@ -76,4 +74,4 @@ public boolean onOptionsItemSelected(MenuItem item) {
return super.onOptionsItemSelected(item);
}
}
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -18,6 +18,7 @@

package de.arnowelzel.android.periodical;

import android.annotation.SuppressLint;
import android.text.format.DateUtils;
import de.arnowelzel.android.periodical.PeriodicalDatabase.DayEntry;
import android.content.Context;
Expand All @@ -41,6 +42,7 @@
/**
* Custom button class to display the calendar cells
*/
@SuppressLint("AppCompatCustomView")
public class CalendarCell extends Button {
/** flag for "is current day" */
protected boolean isCurrent;
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -18,16 +18,16 @@

package de.arnowelzel.android.periodical;

import android.app.ActionBar;
import android.app.Activity;
import android.os.Bundle;
import android.support.v7.app.ActionBar;
import android.support.v7.app.AppCompatActivity;
import android.view.MenuItem;
import android.webkit.WebView;

/**
* Activity to handle the "Help" command
*/
public class HelpActivity extends Activity {
public class HelpActivity extends AppCompatActivity {

/**
* Called when the activity starts
Expand All @@ -43,11 +43,9 @@ public void onCreate(Bundle savedInstanceState) {
view.loadUrl("file:///android_asset/"+getString(R.string.asset_help));

// Activate "back button" in Action Bar if possible
if (android.os.Build.VERSION.SDK_INT >= 11) {
ActionBar actionBar = getActionBar();
assert actionBar != null;
actionBar.setDisplayHomeAsUpEnabled(true);
}
ActionBar actionBar = getSupportActionBar();
assert actionBar != null;
actionBar.setDisplayHomeAsUpEnabled(true);
}

/**
Expand All @@ -64,4 +62,4 @@ public boolean onOptionsItemSelected(MenuItem item) {
return super.onOptionsItemSelected(item);
}
}
}
}
Original file line number Diff line number Diff line change
@@ -1,42 +1,44 @@
/**
* Periodical list activity
* Periodical list activity
* Copyright (C) 2012-2015 Arno Welzel
*
*
* This code is free software: you can redistribute it and/or modify
* it under the terms of the GNU General Public License as published by
* the Free Software Foundation, either version 3 of the License, or
* (at your option) any later version.
*
*
* This program is distributed in the hope that it will be useful,
* but WITHOUT ANY WARRANTY; without even the implied warranty of
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
* GNU General Public License for more details.
*
*
* You should have received a copy of the GNU General Public License
* along with this program. If not, see <http://www.gnu.org/licenses/>.
*/

package de.arnowelzel.android.periodical;

import java.util.Calendar;
import java.util.Iterator;

import android.content.Context;
import android.annotation.SuppressLint;
import android.app.ActionBar;
import android.content.Context;
import android.content.Intent;
import android.os.Bundle;
import android.support.v7.app.ActionBar;
import android.support.v7.app.AppCompatActivity;
import android.support.v7.widget.ListViewCompat;
import android.view.MenuItem;
import android.view.View;
import android.widget.AdapterView;
import android.widget.ArrayAdapter;
import android.widget.ListView;

import java.util.Calendar;
import java.util.Iterator;

import de.arnowelzel.android.periodical.PeriodicalDatabase.DayEntry;

/**
* Activity to handle the "List" command
*/
public class ListActivity extends android.app.ListActivity {
public class ListActivity extends AppCompatActivity implements AdapterView.OnItemClickListener {
/**
* Database for calendar data
*/
Expand Down Expand Up @@ -96,18 +98,19 @@ public void onCreate(Bundle savedInstanceState) {
entries[pos - 1] += "\n" + getString(R.string.event_periodfirst);
}

setListAdapter(new ArrayAdapter<>(this, R.layout.listitem,
entries));

// Set custom view
setContentView(R.layout.listview);

ListViewCompat listView = (ListViewCompat) findViewById(R.id.listview);
listView.setAdapter(new ArrayAdapter<>(this, R.layout.listitem,
entries));
listView.setOnItemClickListener(this);

// Activate "back button" in Action Bar if possible
if (android.os.Build.VERSION.SDK_INT >= 11) {
ActionBar actionBar = getActionBar();
assert actionBar != null;
actionBar.setDisplayHomeAsUpEnabled(true);
}
ActionBar actionBar = getSupportActionBar();
assert actionBar != null;
actionBar.setDisplayHomeAsUpEnabled(true);
}

/**
Expand Down Expand Up @@ -139,7 +142,7 @@ public boolean onOptionsItemSelected(MenuItem item) {
/**
* Handler for opening a list item which will return to the main view
*
* @param l
* @param adapterView
* The ListView where the click happened
*
* @param v
Expand All @@ -152,7 +155,7 @@ public boolean onOptionsItemSelected(MenuItem item) {
* The row id of the item that was clicked
*/
@Override
protected void onListItemClick(ListView l, View v, int position, long id) {
public void onItemClick(AdapterView<?> adapterView, View v, int position, long id) {
// Determine date of clicked item
if (dbMain != null && position >= 0
&& position < dbMain.dayEntries.size()) {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -31,8 +31,10 @@
import android.content.pm.PackageManager;
import android.os.Bundle;
import android.preference.PreferenceManager;
import android.support.annotation.NonNull;
import android.support.v4.app.ActivityCompat;
import android.support.v4.content.ContextCompat;
import android.support.v7.app.AppCompatActivity;
import android.view.GestureDetector;
import android.view.GestureDetector.SimpleOnGestureListener;
import android.view.Menu;
Expand All @@ -43,7 +45,6 @@
import android.widget.TextView;
import android.widget.Toast;
import android.widget.ViewFlipper;
import android.support.annotation.NonNull;

import java.text.SimpleDateFormat;
import java.util.Calendar;
Expand All @@ -52,7 +53,7 @@
/**
* The main activity of the app
*/
public class MainActivity extends Activity {
public class MainActivity extends AppCompatActivity {
final int calButtonIds[] = { R.id.cal01, R.id.cal02, R.id.cal03,
R.id.cal04, R.id.cal05, R.id.cal06, R.id.cal07, R.id.cal08,
R.id.cal09, R.id.cal10, R.id.cal11, R.id.cal12, R.id.cal13,
Expand Down
Loading

0 comments on commit 324d868

Please sign in to comment.