Skip to content

Commit

Permalink
Flattened SettingsActivity, Nickname highlighting, Launcher Icon
Browse files Browse the repository at this point in the history
  • Loading branch information
pstorch committed May 7, 2017
1 parent 8b9c40b commit f84d484
Show file tree
Hide file tree
Showing 11 changed files with 38 additions and 62 deletions.
Binary file added app/src/main/ic_launcher-web.png
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Original file line number Diff line number Diff line change
@@ -1,6 +1,7 @@
package org.pstorch.androidirclogviewer;

import android.content.Intent;
import android.content.SharedPreferences;
import android.os.AsyncTask;
import android.os.Bundle;
import android.preference.PreferenceManager;
Expand Down Expand Up @@ -38,6 +39,7 @@ public class MainActivity extends AppCompatActivity {
private final SimpleDateFormat df = new SimpleDateFormat("yyyy-MM-dd", Locale.US);

private String baseUrl = null;
private String nickname = null;

private BottomNavigationView.OnNavigationItemSelectedListener mOnNavigationItemSelectedListener
= new BottomNavigationView.OnNavigationItemSelectedListener() {
Expand Down Expand Up @@ -115,7 +117,9 @@ protected void onCreate(final Bundle savedInstanceState) {
BottomNavigationView navigation = (BottomNavigationView) findViewById(R.id.navigation);
navigation.setOnNavigationItemSelectedListener(mOnNavigationItemSelectedListener);

baseUrl = PreferenceManager.getDefaultSharedPreferences(this).getString("base_url", null);
final SharedPreferences preferences = PreferenceManager.getDefaultSharedPreferences(this);
baseUrl = preferences.getString("base_url", null);
nickname = preferences.getString("nickname", null);

loadLog();
}
Expand Down Expand Up @@ -150,9 +154,16 @@ private void appendFormatted(final StringBuilder formattedText, final String lin
if (matcher.matches()) {
final String user = matcher.group(2);
final String color = "#" + Integer.toHexString(user.hashCode()).substring(0, 6);
final String message = matcher.group(3);
if (nickname != null && message.contains(nickname)) {
formattedText.append("<b>");
}
formattedText.append(matcher.group(1))
.append("<font color=\"").append(color).append("\"> ").append(user).append(": </font>")
.append(Html.escapeHtml(matcher.group(3)));
.append(Html.escapeHtml(message));
if (nickname != null && message.contains(nickname)) {
formattedText.append("</b>");
}
} else {
formattedText.append("<font color=\"#cccccc\">").append(Html.escapeHtml(line)).append("</font>");
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -2,9 +2,6 @@


import android.annotation.TargetApi;
import android.content.Context;
import android.content.Intent;
import android.content.res.Configuration;
import android.os.Build;
import android.os.Bundle;
import android.preference.ListPreference;
Expand All @@ -15,8 +12,6 @@
import android.support.v7.app.ActionBar;
import android.view.MenuItem;

import java.util.List;

/**
* A {@link PreferenceActivity} that presents a set of application settings. On
* handset devices, settings are presented as a single list. On tablets,
Expand Down Expand Up @@ -59,15 +54,6 @@ public boolean onPreferenceChange(Preference preference, Object value) {
}
};

/**
* Helper method to determine if the device has an extra-large screen. For
* example, 10" tablets are extra-large.
*/
private static boolean isXLargeTablet(Context context) {
return (context.getResources().getConfiguration().screenLayout
& Configuration.SCREENLAYOUT_SIZE_MASK) >= Configuration.SCREENLAYOUT_SIZE_XLARGE;
}

/**
* Binds a preference's summary to its value. More specifically, when the
* preference's value is changed, its summary (line of text below the
Expand All @@ -92,6 +78,8 @@ private static void bindPreferenceSummaryToValue(Preference preference) {
@Override
protected void onCreate(Bundle savedInstanceState) {
super.onCreate(savedInstanceState);
getFragmentManager().beginTransaction().replace(android.R.id.content,
new GeneralPreferenceFragment()).commit();
setupActionBar();
}

Expand All @@ -106,32 +94,6 @@ private void setupActionBar() {
}
}

/**
* {@inheritDoc}
*/
@Override
public boolean onIsMultiPane() {
return isXLargeTablet(this);
}

/**
* {@inheritDoc}
*/
@Override
@TargetApi(Build.VERSION_CODES.HONEYCOMB)
public void onBuildHeaders(List<Header> target) {
loadHeadersFromResource(R.xml.pref_headers, target);
}

/**
* This method stops fragment injection in malicious applications.
* Make sure to deny any unknown fragments here.
*/
protected boolean isValidFragment(String fragmentName) {
return PreferenceFragment.class.getName().equals(fragmentName)
|| GeneralPreferenceFragment.class.getName().equals(fragmentName);
}

/**
* This fragment shows general preferences only. It is used when the
* activity is showing a two-pane settings UI.
Expand All @@ -141,25 +103,28 @@ public static class GeneralPreferenceFragment extends PreferenceFragment {
@Override
public void onCreate(Bundle savedInstanceState) {
super.onCreate(savedInstanceState);
addPreferencesFromResource(R.xml.pref_general);
addPreferencesFromResource(R.xml.preferences);
setHasOptionsMenu(true);

// Bind the summaries of EditText/List/Dialog/Ringtone preferences
// to their values. When their values change, their summaries are
// updated to reflect the new value, per the Android Design
// guidelines.
bindPreferenceSummaryToValue(findPreference("base_url"));
bindPreferenceSummaryToValue(findPreference("nickname"));
}

@Override
public boolean onOptionsItemSelected(MenuItem item) {
int id = item.getItemId();
if (id == android.R.id.home) {
startActivity(new Intent(getActivity(), SettingsActivity.class));
}

@Override
public boolean onOptionsItemSelected(MenuItem item) {
switch (item.getItemId()) {
// Respond to the action bar's Up/Home button
case android.R.id.home:
super.onBackPressed();
return true;
}
return super.onOptionsItemSelected(item);
}
return super.onOptionsItemSelected(item);
}

}
Binary file modified app/src/main/res/mipmap-hdpi/ic_launcher.png
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Binary file modified app/src/main/res/mipmap-mdpi/ic_launcher.png
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Binary file modified app/src/main/res/mipmap-xhdpi/ic_launcher.png
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Binary file modified app/src/main/res/mipmap-xxhdpi/ic_launcher.png
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Binary file modified app/src/main/res/mipmap-xxxhdpi/ic_launcher.png
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
4 changes: 3 additions & 1 deletion app/src/main/res/values/strings.xml
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
<resources>
<string name="app_name">Android IRC LogViewer</string>
<string name="app_name">IRC LogViewer</string>
<string name="title_forward">Forward</string>
<string name="title_refresh">Refresh</string>
<string name="title_back">Back</string>
Expand All @@ -12,5 +12,7 @@

<string name="pref_title_base_url">Base URL</string>
<string name="pref_default_base_url">http://krul.finf.uni-hannover.de/~sammyshp/cgeo-logs</string>
<string name="pref_default_nickname">Nickname</string>
<string name="pref_title_nickname">Nickname</string>

</resources>
11 changes: 0 additions & 11 deletions app/src/main/res/xml/pref_headers.xml

This file was deleted.

Original file line number Diff line number Diff line change
Expand Up @@ -12,5 +12,14 @@
android:singleLine="true"
android:title="@string/pref_title_base_url"/>

<EditTextPreference
android:capitalize="words"
android:defaultValue="@string/pref_default_nickname"
android:inputType="textCapWords"
android:key="nickname"
android:maxLines="1"
android:selectAllOnFocus="true"
android:singleLine="true"
android:title="@string/pref_title_nickname"/>

</PreferenceScreen>

0 comments on commit f84d484

Please sign in to comment.