diff --git a/LICENSE b/LICENSE
old mode 100644
new mode 100755
diff --git a/README.md b/README.md
old mode 100644
new mode 100755
index 37289f51..b34b2344
--- a/README.md
+++ b/README.md
@@ -2,7 +2,7 @@ QR-PTT PushToTalk
=======
QR-PTT PushToTalk is an easy to use ptt over IP Android client for voice and text communication that uses the [Jumble] (https://github.com/Morlunk/Jumble) protocol implementation and has a GPLv3 license. It can be used by companies that need to be in constant communication with their employees (Lone Workers), to give instructions, make comments, report incidents in real time by voice communication or by sending a text message within the app.
- To try it for free enter "demo" as Guard ID and leave Guard PIN field empty.*
+ To try it for free enter "demo" as User ID and leave User PIN field empty.*
Its main features are:
- Easy to use
diff --git a/app/build.gradle b/app/build.gradle
old mode 100644
new mode 100755
index 42c1cc2d..7f321f34
--- a/app/build.gradle
+++ b/app/build.gradle
@@ -1,28 +1,3 @@
-/*
- * Copyright (C) 2014 Andrew Comminos
- *
- * This program 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 .
- */
-
-
-
-
-
-
-
-
-
buildscript {
repositories {
mavenCentral()
@@ -51,8 +26,6 @@ dependencies {
compile files('/home/theo/git/QRPushToTalk/libraries/gson-2.3.1.jar')
}
-
-// Keep my credentials private :^)
def signingFile = file 'signing.gradle';
if (signingFile.exists()) apply from: 'signing.gradle'
@@ -64,8 +37,8 @@ android {
minSdkVersion 14
targetSdkVersion 21
applicationId "com.terracom.qrpttbeta"
- versionCode 80
- versionName "0.9.0"
+ versionCode 82
+ versionName "1.0.0"
testInstrumentationRunner "android.test.InstrumentationTestRunner"
buildConfigField "boolean", "DONATE_NAG", "false"
}
@@ -82,7 +55,6 @@ android {
}
jenkins {
- // Abuse Jenkins environment variables. Neat.
def env = System.getenv()
if (env.containsKey("BUILD_NUMBER") && env.containsKey("BUILD_DISPLAY_NAME")) {
versionCode Integer.parseInt(env.get("BUILD_NUMBER"))
diff --git a/app/src/androidTest/java/com/terracom/qrpttbeta/test/QRPushToTalkSQLTestCase.java b/app/src/androidTest/java/com/terracom/qrpttbeta/test/QRPushToTalkSQLTestCase.java
old mode 100644
new mode 100755
index ea18d5bd..f9db4e7b
--- a/app/src/androidTest/java/com/terracom/qrpttbeta/test/QRPushToTalkSQLTestCase.java
+++ b/app/src/androidTest/java/com/terracom/qrpttbeta/test/QRPushToTalkSQLTestCase.java
@@ -23,15 +23,9 @@
import java.util.UUID;
-/**
- * Test case designed to test operations of QRPushToTalk's database.
- * A new DB is created and destroyed with each test call.
- * Created by andrew on 19/08/14.
- */
public class QRPushToTalkSQLTestCase extends AndroidTestCase {
- /** Database name used in the active test. */
+
private String mDatabaseName;
- /** Database for the active test. */
private QRPushToTalkSQLiteDatabase mDatabase;
@Override
@@ -57,7 +51,6 @@ public void testLocalMuteIgnore() {
long server = 5;
int userId = 1;
- // Test ignore duplicate constraint
for (int i = 0; i < 2; i++) {
mDatabase.addLocalMutedUser(server, userId);
mDatabase.addLocalIgnoredUser(server, userId);
diff --git a/app/src/free/AndroidManifest.xml b/app/src/free/AndroidManifest.xml
old mode 100644
new mode 100755
index 9aaf70e6..28cbc07f
--- a/app/src/free/AndroidManifest.xml
+++ b/app/src/free/AndroidManifest.xml
@@ -1,22 +1,4 @@
-
-
-
diff --git a/app/src/free/ic_launcher-web.png b/app/src/free/ic_launcher-web.png
old mode 100644
new mode 100755
diff --git a/app/src/free/res/drawable-hdpi/ic_launcher.png b/app/src/free/res/drawable-hdpi/ic_launcher.png
old mode 100644
new mode 100755
diff --git a/app/src/free/res/drawable-mdpi/ic_launcher.png b/app/src/free/res/drawable-mdpi/ic_launcher.png
old mode 100644
new mode 100755
diff --git a/app/src/free/res/drawable-xhdpi/ic_launcher.png b/app/src/free/res/drawable-xhdpi/ic_launcher.png
old mode 100644
new mode 100755
diff --git a/app/src/free/res/drawable-xxhdpi/ic_launcher.png b/app/src/free/res/drawable-xxhdpi/ic_launcher.png
old mode 100644
new mode 100755
diff --git a/app/src/free/res/drawable-xxxhdpi/ic_launcher.png b/app/src/free/res/drawable-xxxhdpi/ic_launcher.png
old mode 100644
new mode 100755
diff --git a/app/src/free/res/values/strings.xml b/app/src/free/res/values/strings.xml
old mode 100644
new mode 100755
index cc87ea61..430e8f9e
--- a/app/src/free/res/values/strings.xml
+++ b/app/src/free/res/values/strings.xml
@@ -1,21 +1,4 @@
-
-
- QR PushToTalk BETA
+ QR-PTT PushToTalk
\ No newline at end of file
diff --git a/app/src/free/res/xml/searchable.xml b/app/src/free/res/xml/searchable.xml
old mode 100644
new mode 100755
index ba30745e..8d137b0b
--- a/app/src/free/res/xml/searchable.xml
+++ b/app/src/free/res/xml/searchable.xml
@@ -1,21 +1,4 @@
-
-
-
@@ -74,12 +58,6 @@
android:name="com.terracom.qrpttbeta.service.QRPushToTalkService"
android:enabled="true" />
-
.
- */
-
package com.terracom.qrpttbeta;
public class Constants {
diff --git a/app/src/main/java/com/terracom/qrpttbeta/Settings.java b/app/src/main/java/com/terracom/qrpttbeta/Settings.java
old mode 100644
new mode 100755
index 07c9afb2..dc538691
--- a/app/src/main/java/com/terracom/qrpttbeta/Settings.java
+++ b/app/src/main/java/com/terracom/qrpttbeta/Settings.java
@@ -1,20 +1,3 @@
-/*
- * Copyright (C) 2014 Andrew Comminos
- *
- * This program 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 .
- */
-
package com.terracom.qrpttbeta;
import android.content.Context;
@@ -31,18 +14,11 @@
import java.util.HashSet;
import java.util.Set;
-/**
- * Singleton settings class for universal access to the app's preferences.
- * @author terracom
- */
public class Settings {
public static final String PREF_INPUT_METHOD = "audioInputMethod";
public static final Set ARRAY_INPUT_METHODS;
- /** Voice activity transmits depending on the amplitude of user input. */
public static final String ARRAY_INPUT_METHOD_VOICE = "voiceActivity";
- /** Push to talk transmits on command. */
public static final String ARRAY_INPUT_METHOD_PTT = "ptt";
- /** Continuous transmits always. */
public static final String ARRAY_INPUT_METHOD_CONTINUOUS = "continuous";
public static final String PREF_THRESHOLD = "vadThreshold";
@@ -84,10 +60,6 @@ public class Settings {
public static final Boolean DEFAULT_AUTO_RECONNECT = true;
public static final String PREF_THEME = "theme";
- public static final String ARRAY_THEME_LIGHT = "lightDark";
- public static final String ARRAY_THEME_DARK = "dark";
- public static final String ARRAY_THEME_SOLARIZED_LIGHT = "solarizedLight";
- public static final String ARRAY_THEME_SOLARIZED_DARK = "solarizedDark";
public static final String PREF_CERT = "certificatePath";
public static final String PREF_CERT_PASSWORD = "certificatePassword";
@@ -152,20 +124,13 @@ private Settings(Context ctx) {
}
public String getInputMethod() {
- //String method = preferences.getString(PREF_INPUT_METHOD, ARRAY_INPUT_METHOD_VOICE);
- String method = preferences.getString(PREF_INPUT_METHOD,ARRAY_INPUT_METHOD_PTT);
- if(!ARRAY_INPUT_METHODS.contains(method)) {
- // Set default method for users who used to use handset mode before removal.
- //method = ARRAY_INPUT_METHOD_VOICE;
+ String method = preferences.getString(PREF_INPUT_METHOD, ARRAY_INPUT_METHOD_PTT);
+ if (!ARRAY_INPUT_METHODS.contains(method)) {
method = ARRAY_INPUT_METHOD_PTT;
}
return method;
}
- /**
- * Converts the preference input method value to the one used to connect to a server via Jumble.
- * @return An input method value used to instantiate a Jumble service.
- */
public int getJumbleInputMethod() {
String inputMethod = getInputMethod();
if (ARRAY_INPUT_METHOD_VOICE.equals(inputMethod)) {
@@ -179,7 +144,7 @@ public int getJumbleInputMethod() {
}
public void setInputMethod(String inputMethod) {
- if(ARRAY_INPUT_METHOD_VOICE.equals(inputMethod) ||
+ if (ARRAY_INPUT_METHOD_VOICE.equals(inputMethod) ||
ARRAY_INPUT_METHOD_PTT.equals(inputMethod) ||
ARRAY_INPUT_METHOD_CONTINUOUS.equals(inputMethod)) {
preferences.edit().putString(PREF_INPUT_METHOD, "ptt").apply();
@@ -197,11 +162,11 @@ public int getInputQuality() {
}
public float getAmplitudeBoostMultiplier() {
- return (float)preferences.getInt(Settings.PREF_AMPLITUDE_BOOST, DEFAULT_AMPLITUDE_BOOST)/100;
+ return (float) preferences.getInt(Settings.PREF_AMPLITUDE_BOOST, DEFAULT_AMPLITUDE_BOOST) / 100;
}
public float getDetectionThreshold() {
- return (float)preferences.getInt(PREF_THRESHOLD, DEFAULT_THRESHOLD)/100;
+ return (float) preferences.getInt(PREF_THRESHOLD, DEFAULT_THRESHOLD) / 100;
}
public int getPushToTalkKey() {
@@ -212,58 +177,30 @@ public String getHotCorner() {
return preferences.getString(PREF_HOT_CORNER_KEY, DEFAULT_HOT_CORNER);
}
- /**
- * Returns whether or not the hot corner is enabled.
- * @return true if a hot corner should be shown.
- */
public boolean isHotCornerEnabled() {
return !ARRAY_HOT_CORNER_NONE.equals(preferences.getString(PREF_HOT_CORNER_KEY, DEFAULT_HOT_CORNER));
}
- /**
- * Returns the view gravity of the hot corner, or 0 if hot corner is disabled.
- * @return A {@link android.view.Gravity} value, or 0 if disabled.
- */
public int getHotCornerGravity() {
String hc = getHotCorner();
- if(ARRAY_HOT_CORNER_BOTTOM_LEFT.equals(hc)) {
+ if (ARRAY_HOT_CORNER_BOTTOM_LEFT.equals(hc)) {
return Gravity.LEFT | Gravity.BOTTOM;
- } else if(ARRAY_HOT_CORNER_BOTTOM_RIGHT.equals(hc)) {
+ } else if (ARRAY_HOT_CORNER_BOTTOM_RIGHT.equals(hc)) {
return Gravity.RIGHT | Gravity.BOTTOM;
- } else if(ARRAY_HOT_CORNER_TOP_LEFT.equals(hc)) {
+ } else if (ARRAY_HOT_CORNER_TOP_LEFT.equals(hc)) {
return Gravity.LEFT | Gravity.TOP;
- } else if(ARRAY_HOT_CORNER_TOP_RIGHT.equals(hc)) {
+ } else if (ARRAY_HOT_CORNER_TOP_RIGHT.equals(hc)) {
return Gravity.RIGHT | Gravity.TOP;
}
return 0;
}
- /**
- * @return the resource ID of the user-defined theme.
- */
- /*public int getTheme() {
- String theme = preferences.getString(PREF_THEME, ARRAY_THEME_LIGHT);
- if(ARRAY_THEME_LIGHT.equals(theme))
- return R.style.Theme_QRPushToTalk;
- else if(ARRAY_THEME_DARK.equals(theme))
- return R.style.Theme_QRPushToTalk_Dark;
- else if(ARRAY_THEME_SOLARIZED_LIGHT.equals(theme))
- return R.style.Theme_QRPushToTalk_Solarized_Light;
- else if(ARRAY_THEME_SOLARIZED_DARK.equals(theme))
- return R.style.Theme_QRPushToTalk_Solarized_Dark;
- return -1;
- }*/
-
public int getTheme() {
return R.style.Theme_QRPushToTalk_Solarized_Light;
}
- /**
- * Attempts to read the certificate from the path specified in settings.
- * @return The parsed bytes of the certificate, or null otherwise.
- */
public byte[] getCertificate() {
try {
FileInputStream inputStream = new FileInputStream(preferences.getString(PREF_CERT, ""));
diff --git a/app/src/main/java/com/terracom/qrpttbeta/app/DrawerAdapter.java b/app/src/main/java/com/terracom/qrpttbeta/app/DrawerAdapter.java
old mode 100644
new mode 100755
index 280ae563..18497547
--- a/app/src/main/java/com/terracom/qrpttbeta/app/DrawerAdapter.java
+++ b/app/src/main/java/com/terracom/qrpttbeta/app/DrawerAdapter.java
@@ -1,20 +1,3 @@
-/*
- * Copyright (C) 2014 Andrew Comminos
- *
- * This program 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 .
- */
-
package com.terracom.qrpttbeta.app;
import android.content.Context;
@@ -28,35 +11,21 @@
import com.terracom.qrpttbeta.R;
-/**
- * Created by andrew on 01/08/13.
- */
public class DrawerAdapter extends ArrayAdapter {
- /**
- * Provides context for the drawer module.
- */
public interface DrawerDataProvider {
- /**
- * @return true if connected, false otherwise.
- */
public boolean isConnected();
- /**
- * @return The name of the connected server. If not connected, then null.
- */
+
public String getConnectedServerName();
}
- // Drawer rows, integer value is id
public static final int HEADER_CONNECTED_SERVER = 0;
public static final int ITEM_SERVER = 1;
public static final int ITEM_INFO = 2;
public static final int ITEM_ACCESS_TOKENS = 3;
public static final int ITEM_PINNED_CHANNELS = 4;
- public static final int HEADER_SERVERS = 5;
public static final int ITEM_FAVOURITES = 6;
-// public static final int ITEM_LAN = 7;
public static final int ITEM_PUBLIC = 8;
public static final int HEADER_GENERAL = 9;
public static final int ITEM_SETTINGS = 10;
@@ -64,8 +33,6 @@ public interface DrawerDataProvider {
private static final int HEADER_TYPE = 0;
private static final int ITEM_TYPE = 1;
- // TODO clean this up.
-
public static class DrawerRow {
int id;
String title;
@@ -99,16 +66,8 @@ public DrawerAdapter(Context context, DrawerDataProvider provider) {
mProvider = provider;
add(new DrawerAdapter.DrawerHeader(HEADER_CONNECTED_SERVER, context.getString(R.string.drawer_not_connected)));
add(new DrawerAdapter.DrawerItem(ITEM_SERVER, context.getString(R.string.drawer_server), R.drawable.ic_action_channels));
-// add(new DrawerAdapter.DrawerItem(ITEM_INFO, context.getString(R.string.information), R.drawable.ic_action_info_dark));
add(new DrawerAdapter.DrawerItem(ITEM_FAVOURITES, context.getString(R.string.drawer_favorites), R.drawable.ic_action_favourite_on));
-// add(new DrawerAdapter.DrawerItem(ITEM_ACCESS_TOKENS, "Disconnect", R.drawable.ic_action_save));
-// add(new DrawerAdapter.DrawerItem(ITEM_PINNED_CHANNELS, context.getString(R.string.drawer_pinned), R.drawable.ic_action_comment));
-// add(new DrawerAdapter.DrawerHeader(HEADER_SERVERS, context.getString(R.string.drawer_header_servers)));
-// add(new DrawerAdapter.DrawerItem(ITEM_FAVOURITES, context.getString(R.string.drawer_favorites), R.drawable.ic_action_favourite_on));
-// add(new DrawerAdapter.DrawerItem(ITEM_LAN, context.getString(R.string.drawer_lan), R.drawable.ic_action_fullscreen)); // Coming soon, TODO
-// add(new DrawerAdapter.DrawerItem(ITEM_PUBLIC, context.getString(R.string.drawer_public), R.drawable.ic_action_search));
add(new DrawerAdapter.DrawerHeader(HEADER_GENERAL, context.getString(R.string.general)));
-// add(new DrawerAdapter.DrawerItem(ITEM_FAVOURITES, context.getString(R.string.drawer_favorites), R.drawable.ic_action_favourite_on));
add(new DrawerAdapter.DrawerItem(ITEM_SETTINGS, context.getString(R.string.action_settings), R.drawable.ic_action_settings));
add(new DrawerAdapter.DrawerItem(ITEM_PUBLIC, context.getString(R.string.drawer_public), R.drawable.ic_action_error));
@@ -118,21 +77,21 @@ public DrawerAdapter(Context context, DrawerDataProvider provider) {
public View getView(int position, View convertView, ViewGroup parent) {
View v = convertView;
int viewType = getItemViewType(position);
- if(v == null) {
- if(viewType == HEADER_TYPE)
+ if (v == null) {
+ if (viewType == HEADER_TYPE)
v = LayoutInflater.from(getContext()).inflate(R.layout.list_drawer_header, parent, false);
- else if(viewType == ITEM_TYPE)
+ else if (viewType == ITEM_TYPE)
v = LayoutInflater.from(getContext()).inflate(R.layout.list_drawer_item, parent, false);
}
- if(viewType == HEADER_TYPE) {
+ if (viewType == HEADER_TYPE) {
DrawerHeader header = (DrawerHeader) getItem(position);
TextView title = (TextView) v.findViewById(R.id.drawer_header_title);
- switch((int) getItemId(position)) {
+ switch ((int) getItemId(position)) {
case HEADER_CONNECTED_SERVER:
- if(mProvider.isConnected()) {
+ if (mProvider.isConnected()) {
title.setText(mProvider.getConnectedServerName());
break;
}
@@ -140,7 +99,7 @@ else if(viewType == ITEM_TYPE)
title.setText(header.title);
break;
}
- } else if(viewType == ITEM_TYPE) {
+ } else if (viewType == ITEM_TYPE) {
DrawerItem item = (DrawerItem) getItem(position);
TextView title = (TextView) v.findViewById(R.id.drawer_item_title);
ImageView icon = (ImageView) v.findViewById(R.id.drawer_item_icon);
@@ -149,10 +108,9 @@ else if(viewType == ITEM_TYPE)
boolean enabled = isEnabled(position);
- // Set text and icon color+alpha based on enabled/disabled state
int textColor = title.getCurrentTextColor();
- textColor &= 0x00FFFFFF; // Clear alpha bits
- textColor |= enabled ? 0xFF000000 : 0x55000000; // Set alpha bits depending on whether the state is enabled or disabled
+ textColor &= 0x00FFFFFF;
+ textColor |= enabled ? 0xFF000000 : 0x55000000;
title.setTextColor(textColor);
icon.setColorFilter(textColor, PorterDuff.Mode.MULTIPLY);
@@ -167,9 +125,9 @@ public long getItemId(int position) {
}
public DrawerRow getItemWithId(int id) {
- for(int x=0;x.
- */
-
package com.terracom.qrpttbeta.app;
-import android.app.Activity;
import android.app.AlertDialog;
import android.app.ProgressDialog;
import android.content.ComponentName;
@@ -38,7 +20,6 @@
import android.support.v4.widget.DrawerLayout;
import android.support.v7.app.ActionBarActivity;
import android.support.v7.app.ActionBarDrawerToggle;
-import android.util.Log;
import android.view.KeyEvent;
import android.view.Menu;
import android.view.MenuItem;
@@ -66,17 +47,13 @@
import com.terracom.qrpttbeta.db.PublicServer;
import com.terracom.qrpttbeta.preference.QRPushToTalkCertificateGenerateTask;
import com.terracom.qrpttbeta.preference.Preferences;
-import com.terracom.qrpttbeta.servers.FavouriteServerAdapter;
import com.terracom.qrpttbeta.servers.FavouriteServerListFragment;
-import com.terracom.qrpttbeta.servers.PublicServerListFragment;
import com.terracom.qrpttbeta.servers.ServerEditFragment;
import com.terracom.qrpttbeta.service.QRPushToTalkService;
import com.terracom.qrpttbeta.util.JumbleServiceFragment;
import com.terracom.qrpttbeta.util.JumbleServiceProvider;
import com.terracom.qrpttbeta.util.QRPushToTalkTrustStore;
-import org.spongycastle.util.encoders.Hex;
-
import java.io.ByteArrayInputStream;
import java.io.File;
import java.net.MalformedURLException;
@@ -88,18 +65,12 @@
import java.security.cert.X509Certificate;
import java.util.ArrayList;
import java.util.List;
-import java.util.StringTokenizer;
-
-import info.guardianproject.onionkit.ui.OrbotHelper;
-
public class QRPushToTalkActivity extends ActionBarActivity implements ListView.OnItemClickListener,
FavouriteServerListFragment.ServerConnectHandler, JumbleServiceProvider, DatabaseProvider,
SharedPreferences.OnSharedPreferenceChangeListener, DrawerAdapter.DrawerDataProvider,
ServerEditFragment.ServerEditListener {
- /**
- * If specified, the provided integer drawer fragment ID is shown when the activity is created.
- */
+
public static final String EXTRA_DRAWER_FRAGMENT = "drawer_fragment";
public static final String LastChannelPreference = "lastchannelloggedprefs";
@@ -108,7 +79,6 @@ public class QRPushToTalkActivity extends ActionBarActivity implements ListView.
private QRPushToTalkService.QRPushToTalkBinder mService;
private QRPushToTalkDatabase mDatabase;
private Settings mSettings;
-
private ActionBarDrawerToggle mDrawerToggle;
private DrawerLayout mDrawerLayout;
private ListView mDrawerList;
@@ -118,7 +88,6 @@ public class QRPushToTalkActivity extends ActionBarActivity implements ListView.
private AlertDialog mErrorDialog;
private AlertDialog.Builder mDisconnectPromptBuilder;
- /** List of fragments to be notified about service state changes. */
private List mServiceFragments = new ArrayList();
private ServiceConnection mConnection = new ServiceConnection() {
@@ -127,18 +96,17 @@ public void onServiceConnected(ComponentName name, IBinder service) {
mService = (QRPushToTalkService.QRPushToTalkBinder) service;
try {
mService.registerObserver(mObserver);
- mService.clearChatNotifications(); // Clear chat notifications on resume.
+ mService.clearChatNotifications();
} catch (RemoteException e) {
e.printStackTrace();
}
mDrawerAdapter.notifyDataSetChanged();
- for(JumbleServiceFragment fragment : mServiceFragments)
+ for (JumbleServiceFragment fragment : mServiceFragments)
fragment.setServiceBound(true);
- // Re-show server list if we're showing a fragment that depends on the service.
try {
- if(getSupportFragmentManager().findFragmentById(R.id.content_frame) instanceof JumbleServiceFragment &&
+ if (getSupportFragmentManager().findFragmentById(R.id.content_frame) instanceof JumbleServiceFragment &&
mService.getConnectionState() != JumbleService.STATE_CONNECTED) {
loadDrawerFragment(DrawerAdapter.ITEM_FAVOURITES);
}
@@ -164,15 +132,14 @@ public void onConnected() throws RemoteException {
updateConnectionState(getService());
}
- @Override
- public void onConnecting() throws RemoteException {
- updateConnectionState(getService());
- }
+ @Override
+ public void onConnecting() throws RemoteException {
+ updateConnectionState(getService());
+ }
@Override
public void onDisconnected(JumbleException e) throws RemoteException {
- // Re-show server list if we're showing a fragment that depends on the service.
- if(getSupportFragmentManager().findFragmentById(R.id.content_frame) instanceof JumbleServiceFragment) {
+ if (getSupportFragmentManager().findFragmentById(R.id.content_frame) instanceof JumbleServiceFragment) {
loadDrawerFragment(DrawerAdapter.ITEM_FAVOURITES);
}
mDrawerAdapter.notifyDataSetChanged();
@@ -190,42 +157,14 @@ public void onTLSHandshakeFailed(ParcelableByteArray cert) throws RemoteExceptio
CertificateFactory certFactory = CertificateFactory.getInstance("X.509");
final X509Certificate x509 = (X509Certificate) certFactory.generateCertificate(new ByteArrayInputStream(certBytes));
- //AlertDialog.Builder adb = new AlertDialog.Builder(QRPushToTalkActivity.this);
- //adb.setTitle(R.string.untrusted_certificate);
try {
MessageDigest digest = MessageDigest.getInstance("SHA-1");
byte[] certDigest = digest.digest(x509.getEncoded());
- String hexDigest = new String(Hex.encode(certDigest));
- /*adb.setMessage(getString(R.string.certificate_info,
- x509.getSubjectDN().getName(),
- x509.getNotBefore().toString(),
- x509.getNotAfter().toString(),
- hexDigest));*/
} catch (NoSuchAlgorithmException e) {
e.printStackTrace();
- //adb.setMessage(x509.toString());
}
- /*adb.setPositiveButton(R.string.allow, new DialogInterface.OnClickListener() {
- @Override
- public void onClick(DialogInterface dialog, int which) {
- // Try to add to trust store
- try {
- String alias = lastServer.getHost();
- KeyStore trustStore = QRPushToTalkTrustStore.getTrustStore(QRPushToTalkActivity.this);
- trustStore.setCertificateEntry(alias, x509);
- QRPushToTalkTrustStore.saveTrustStore(QRPushToTalkActivity.this, trustStore);
- Toast.makeText(QRPushToTalkActivity.this, R.string.trust_added, Toast.LENGTH_LONG).show();
- connectToServer(lastServer);
- } catch (Exception e) {
- e.printStackTrace();
- Toast.makeText(QRPushToTalkActivity.this, R.string.trust_add_failed, Toast.LENGTH_LONG).show();
- }
- }
- });
- adb.setNegativeButton(R.string.wizard_cancel, null);
- adb.show();*/
try {
String alias = lastServer.getHost();
KeyStore trustStore = QRPushToTalkTrustStore.getTrustStore(QRPushToTalkActivity.this);
@@ -263,7 +202,7 @@ protected void onCreate(Bundle savedInstanceState) {
SharedPreferences preferences = PreferenceManager.getDefaultSharedPreferences(this);
preferences.registerOnSharedPreferenceChangeListener(this);
- mDatabase = new QRPushToTalkSQLiteDatabase(this); // TODO add support for cloud storage
+ mDatabase = new QRPushToTalkSQLiteDatabase(this);
mDatabase.open();
mDrawerLayout = (DrawerLayout) findViewById(R.id.drawer_layout);
@@ -282,7 +221,6 @@ public void onDrawerStateChanged(int newState) {
super.onDrawerStateChanged(newState);
try {
- // Prevent push to talk from getting stuck on when the drawer is opened.
if (getService() != null && getService().getConnectionState() == JumbleService.STATE_CONNECTED && getService().isTalking() && !mSettings.isPushToTalkToggle()) {
getService().setTalkingState(false);
}
@@ -301,8 +239,7 @@ public void onDrawerOpened(View drawerView) {
getSupportActionBar().setDisplayHomeAsUpEnabled(true);
getSupportActionBar().setHomeButtonEnabled(true);
- // Tint logo to theme
- int iconColor = getTheme().obtainStyledAttributes(new int[] { android.R.attr.textColorPrimaryInverse }).getColor(0, -1);
+ int iconColor = getTheme().obtainStyledAttributes(new int[]{android.R.attr.textColorPrimaryInverse}).getColor(0, -1);
Drawable logo = getResources().getDrawable(R.drawable.ic_home);
logo.setColorFilter(iconColor, PorterDuff.Mode.MULTIPLY);
getSupportActionBar().setLogo(logo);
@@ -313,7 +250,8 @@ public void onDrawerOpened(View drawerView) {
@Override
public void onClick(DialogInterface dialog, int which) {
try {
- if(mService != null && mService.getConnectionState() == JumbleService.STATE_CONNECTED) mService.disconnect();
+ if (mService != null && mService.getConnectionState() == JumbleService.STATE_CONNECTED)
+ mService.disconnect();
loadDrawerFragment(DrawerAdapter.ITEM_FAVOURITES);
} catch (RemoteException e) {
e.printStackTrace();
@@ -323,7 +261,7 @@ public void onClick(DialogInterface dialog, int which) {
dadb.setNegativeButton(android.R.string.cancel, null);
mDisconnectPromptBuilder = dadb;
- if(savedInstanceState == null) {
+ if (savedInstanceState == null) {
if (getIntent() != null && getIntent().hasExtra(EXTRA_DRAWER_FRAGMENT)) {
loadDrawerFragment(getIntent().getIntExtra(EXTRA_DRAWER_FRAGMENT,
DrawerAdapter.ITEM_FAVOURITES));
@@ -332,14 +270,11 @@ public void onClick(DialogInterface dialog, int which) {
}
}
- // If we're given a Mumble URL to show, open up a server edit fragment.
- if(getIntent() != null &&
+ if (getIntent() != null &&
Intent.ACTION_VIEW.equals(getIntent().getAction())) {
String url = getIntent().getDataString();
try {
Server server = MumbleURLParser.parseURL(url);
-
- // Open a dialog prompting the user to add the Mumble server.
Bundle args = new Bundle();
args.putBoolean("save", false);
args.putParcelable("server", server);
@@ -350,7 +285,7 @@ public void onClick(DialogInterface dialog, int which) {
e.printStackTrace();
}
}
- if(mSettings.isFirstRun()) showSetupWizard();
+ if (mSettings.isFirstRun()) showSetupWizard();
}
@Override
@@ -373,9 +308,9 @@ protected void onPause() {
mErrorDialog.dismiss();
if (mConnectingDialog != null)
mConnectingDialog.dismiss();
- if(mService != null)
+ if (mService != null)
try {
- for(JumbleServiceFragment fragment : mServiceFragments)
+ for (JumbleServiceFragment fragment : mServiceFragments)
fragment.setServiceBound(false);
mService.unregisterObserver(mObserver);
} catch (RemoteException e) {
@@ -391,10 +326,10 @@ protected void onDestroy() {
mDatabase.close();
- if(!ServerEditFragment.CompanyNameStr.equals("")){
- SharedPreferences mysettings = getSharedPreferences(LastChannelPreference,0);
+ if (!ServerEditFragment.CompanyNameStr.equals("")) {
+ SharedPreferences mysettings = getSharedPreferences(LastChannelPreference, 0);
SharedPreferences.Editor myEditor = mysettings.edit();
- myEditor.putString("LastChannel",ServerEditFragment.CompanyNameStr);
+ myEditor.putString("LastChannel", ServerEditFragment.CompanyNameStr);
myEditor.commit();
}
@@ -406,19 +341,13 @@ protected void onDestroy() {
public boolean onPrepareOptionsMenu(Menu menu) {
MenuItem disconnectButton = menu.findItem(R.id.action_disconnect);
disconnectButton.setVisible(false);
- /*try {
- disconnectButton.setVisible(mService != null && mService.getConnectionState() == JumbleService.STATE_CONNECTED);
- } catch (RemoteException e) {
- e.printStackTrace();
- }*/
- // Color the action bar icons to the primary text color of the theme.
int foregroundColor = getSupportActionBar().getThemedContext()
- .obtainStyledAttributes(new int[] { android.R.attr.textColor })
+ .obtainStyledAttributes(new int[]{android.R.attr.textColor})
.getColor(0, -1);
- for(int x=0;x parent, View view, int position, long id)
loadDrawerFragment((int) id);
}
- /**
- * Shows a nice looking setup wizard to guide the user through the app's settings.
- * Will do nothing if it isn't the first launch.
- */
- /*private void showSetupWizard() {
- // Prompt the user to generate a certificate, FIXME
- if(mSettings.isUsingCertificate()) return;
- AlertDialog.Builder adb = new AlertDialog.Builder(this);
- adb.setTitle(R.string.first_run_generate_certificate_title);
- adb.setMessage(R.string.first_run_generate_certificate);
- adb.setPositiveButton(R.string.generate, new DialogInterface.OnClickListener() {
- @Override
- public void onClick(DialogInterface dialog, int which) {
- QRPushToTalkCertificateGenerateTask generateTask = new QRPushToTalkCertificateGenerateTask(QRPushToTalkActivity.this) {
- @Override
- protected void onPostExecute(File result) {
- super.onPostExecute(result);
- if(result != null) mSettings.setCertificatePath(result.getAbsolutePath());
- }
- };
- generateTask.execute();
- }
- });
- adb.show();
- mSettings.setFirstRun(false);
-
- // TODO: finish wizard
-// Intent intent = new Intent(this, WizardActivity.class);
-// startActivity(intent);
- }*/
-
private void showSetupWizard() {
- // Prompt the user to generate a certificate, FIXME
- if(mSettings.isUsingCertificate()) return;
+ if (mSettings.isUsingCertificate()) return;
AlertDialog.Builder adb = new AlertDialog.Builder(this);
adb.setTitle(R.string.first_run_generate_certificate_title);
adb.setMessage(R.string.first_run_generate_certificate);
@@ -576,7 +455,7 @@ public void onClick(DialogInterface dialog, int which) {
@Override
protected void onPostExecute(File result) {
super.onPostExecute(result);
- if(result != null) mSettings.setCertificatePath(result.getAbsolutePath());
+ if (result != null) mSettings.setCertificatePath(result.getAbsolutePath());
}
};
generateTask.execute();
@@ -586,21 +465,13 @@ protected void onPostExecute(File result) {
@Override
protected void onPostExecute(File result) {
super.onPostExecute(result);
- if(result != null) mSettings.setCertificatePath(result.getAbsolutePath());
+ if (result != null) mSettings.setCertificatePath(result.getAbsolutePath());
}
};
generateTask.execute();
- //adb.show();
mSettings.setFirstRun(false);
-
- // TODO: finish wizard
-// Intent intent = new Intent(this, WizardActivity.class);
-// startActivity(intent);
}
- /**
- * Loads a fragment from the drawer.
- */
private void loadDrawerFragment(int fragmentId) {
Class extends Fragment> fragmentClass = null;
Bundle args = new Bundle();
@@ -613,16 +484,10 @@ private void loadDrawerFragment(int fragmentId) {
break;
case DrawerAdapter.ITEM_ACCESS_TOKENS:
try {
- //if(getService().isConnected()){
- if(mService.getConnectionState() == JumbleService.STATE_CONNECTED){
- //getService().disconnect();
+ if (mService.getConnectionState() == JumbleService.STATE_CONNECTED) {
mService.disconnect();
- //mDisconnectPromptBuilder.show();
loadDrawerFragment(DrawerAdapter.ITEM_FAVOURITES);
- /*if(mService.isConnected()){
- mService.disconnect();
- }*/
- }else{
+ } else {
loadDrawerFragment(DrawerAdapter.ITEM_FAVOURITES);
Toast.makeText(QRPushToTalkActivity.this, "You are not connected!", Toast.LENGTH_LONG).show();
}
@@ -630,16 +495,7 @@ private void loadDrawerFragment(int fragmentId) {
loadDrawerFragment(DrawerAdapter.ITEM_FAVOURITES);
e.printStackTrace();
}
- /*fragmentClass = AccessTokenFragment.class;
- try {
- args.putLong("server", mService.getConnectedServer().getId());
- args.putStringArrayList("access_tokens", (ArrayList) mDatabase.getAccessTokens(mService.getConnectedServer().getId()));
- } catch (RemoteException e) {
- e.printStackTrace();
- }*/
- //fragmentClass = PublicServerListFragment.class;
fragmentClass = FavouriteServerListFragment.class;
- //fragmentClass = ChannelFragment.class;
break;
case DrawerAdapter.ITEM_PINNED_CHANNELS:
fragmentClass = ChannelFragment.class;
@@ -650,19 +506,13 @@ private void loadDrawerFragment(int fragmentId) {
break;
case DrawerAdapter.ITEM_PUBLIC:
try {
- //if(getService().isConnected()){
- if(mService.getConnectionState() == JumbleService.STATE_CONNECTED){
- //getService().disconnect();
+ if (mService.getConnectionState() == JumbleService.STATE_CONNECTED) {
mService.disconnect();
finish();
fragmentClass = ChannelFragment.class;
- //System.exit(0);
- }
- else{
+ } else {
finish();
fragmentClass = FavouriteServerListFragment.class;
- //fragmentClass = PublicServerListFragment.class;
- //System.exit(0);
}
} catch (Exception e) {
finish();
@@ -680,55 +530,17 @@ private void loadDrawerFragment(int fragmentId) {
}
Fragment fragment = Fragment.instantiate(this, fragmentClass.getName(), args);
getSupportFragmentManager().beginTransaction()
- .replace(R.id.content_frame, fragment, fragmentClass.getName())
- .setTransition(FragmentTransaction.TRANSIT_FRAGMENT_FADE)
- .commit();
+ .replace(R.id.content_frame, fragment, fragmentClass.getName())
+ .setTransition(FragmentTransaction.TRANSIT_FRAGMENT_FADE)
+ .commit();
setTitle(mDrawerAdapter.getItemWithId(fragmentId).title);
}
public void connectToServer(final Server server) {
- // Check if we're already connected to a server; if so, inform user.
try {
- if(mService != null && mService.getConnectionState() == JumbleService.STATE_CONNECTED) {
- /*AlertDialog.Builder adb = new AlertDialog.Builder(this);
- adb.setMessage(R.string.reconnect_dialog_message);
- adb.setPositiveButton(R.string.connect, new DialogInterface.OnClickListener() {
- @Override
- public void onClick(DialogInterface dialog, int which) {
- try {
- // Register an observer to reconnect to the new server once disconnected.
- mService.registerObserver(new JumbleObserver() {
- @Override
- public void onDisconnected(JumbleException e) throws RemoteException {
- connectToServer(server);
- mService.unregisterObserver(this);
- }
- });
- mService.disconnect();
- } catch (RemoteException e) {
- e.printStackTrace();
- }
- }
- });
- adb.setNegativeButton(android.R.string.cancel, null);
- adb.show();*/
- /*try {
- // Register an observer to reconnect to the new server once disconnected.
- mService.registerObserver(new JumbleObserver() {
- @Override
- public void onDisconnected(JumbleException e) throws RemoteException {
- connectToServer(server);
- mService.unregisterObserver(this);
- }
- });
- mService.disconnect();
- } catch (RemoteException e) {
- e.printStackTrace();
- }
- return;*/
- if(FavouriteServerListFragment.myEditedflag){
+ if (mService != null && mService.getConnectionState() == JumbleService.STATE_CONNECTED) {
+ if (FavouriteServerListFragment.myEditedflag) {
try {
- // Register an observer to reconnect to the new server once disconnected.
mService.registerObserver(new JumbleObserver() {
@Override
public void onDisconnected(JumbleException e) throws RemoteException {
@@ -751,18 +563,8 @@ public void onDisconnected(JumbleException e) throws RemoteException {
e.printStackTrace();
}
- /*// Prompt to start Orbot if enabled but not running
- if (mSettings.isTorEnabled()) {
- OrbotHelper orbotHelper = new OrbotHelper(this);
- if (!orbotHelper.isOrbotRunning()) {
- orbotHelper.requestOrbotStart(this);
- return;
- }
- }*/
-
-
- SharedPreferences mysettings = getSharedPreferences(LastChannelPreference,0);
- nameOfSavedLastLoggedChannel = mysettings.getString("LastChannel","");
+ SharedPreferences mysettings = getSharedPreferences(LastChannelPreference, 0);
+ nameOfSavedLastLoggedChannel = mysettings.getString("LastChannel", "");
ServerConnectTask connectTask = new ServerConnectTask(this, mDatabase);
@@ -773,11 +575,8 @@ public void connectToPublicServer(final PublicServer server) {
AlertDialog.Builder alertBuilder = new AlertDialog.Builder(this);
final Settings settings = Settings.getInstance(this);
-
- // Allow username entry
final EditText usernameField = new EditText(this);
usernameField.setHint(settings.getDefaultUsername());
- //usernameField.setHint("Leave empty, a demo GuardID will be used");
alertBuilder.setView(usernameField);
alertBuilder.setTitle(R.string.connectToServer);
@@ -786,7 +585,7 @@ public void connectToPublicServer(final PublicServer server) {
@Override
public void onClick(DialogInterface dialog, int which) {
PublicServer newServer = server;
- if(!usernameField.getText().toString().equals(""))
+ if (!usernameField.getText().toString().equals(""))
newServer.setUsername(usernameField.getText().toString());
else
newServer.setUsername(settings.getDefaultUsername());
@@ -805,13 +604,6 @@ private void setStayAwake(boolean stayAwake) {
}
}
- /**
- * Updates the activity to represent the connection state of the given service.
- * Will show reconnecting dialog if reconnecting, dismiss otherwise, etc.
- * Basically, this service will do catch-up if the activity wasn't bound to receive
- * connection state updates.
- * @param service A bound IJumbleService.
- */
private void updateConnectionState(IJumbleService service) throws RemoteException {
if (mConnectingDialog != null)
mConnectingDialog.dismiss();
@@ -841,7 +633,6 @@ public void onCancel(DialogInterface dialog) {
mConnectingDialog.show();
break;
case JumbleService.STATE_CONNECTION_LOST:
- // Only bother the user if the error hasn't already been shown.
if (!getService().isErrorShown()) {
JumbleException error = getService().getConnectionError();
AlertDialog.Builder ab = new AlertDialog.Builder(QRPushToTalkActivity.this);
@@ -883,10 +674,6 @@ public void serverInfoUpdated() {
loadDrawerFragment(DrawerAdapter.ITEM_FAVOURITES);
}
- /*
- * HERE BE IMPLEMENTATIONS
- */
-
@Override
public QRPushToTalkService.QRPushToTalkBinder getService() {
return mService;
@@ -909,9 +696,8 @@ public void removeServiceFragment(JumbleServiceFragment fragment) {
@Override
public void onSharedPreferenceChanged(SharedPreferences sharedPreferences, String key) {
- if(Settings.PREF_THEME.equals(key)) {
- // Recreate activity when theme is changed
- if(Build.VERSION.SDK_INT >= 11)
+ if (Settings.PREF_THEME.equals(key)) {
+ if (Build.VERSION.SDK_INT >= 11)
recreate();
else {
Intent intent = new Intent(this, QRPushToTalkActivity.class);
@@ -936,7 +722,7 @@ public boolean isConnected() {
@Override
public String getConnectedServerName() {
try {
- if(mService != null && mService.getConnectionState() == JumbleService.STATE_CONNECTED) {
+ if (mService != null && mService.getConnectionState() == JumbleService.STATE_CONNECTED) {
Server server = mService.getConnectedServer();
return server.getName().equals("") ? server.getHost() : server.getName();
}
diff --git a/app/src/main/java/com/terracom/qrpttbeta/app/ServerConnectTask.java b/app/src/main/java/com/terracom/qrpttbeta/app/ServerConnectTask.java
old mode 100644
new mode 100755
index 412f5ab7..d9e54434
--- a/app/src/main/java/com/terracom/qrpttbeta/app/ServerConnectTask.java
+++ b/app/src/main/java/com/terracom/qrpttbeta/app/ServerConnectTask.java
@@ -1,20 +1,3 @@
-/*
- * Copyright (C) 2014 Andrew Comminos
- *
- * This program 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 .
- */
-
package com.terracom.qrpttbeta.app;
import android.content.Context;
@@ -34,10 +17,6 @@
import java.util.ArrayList;
-/**
- * Constructs an intent for connection to a QRPushToTalkService and executes it.
- * Created by andrew on 20/08/14.
- */
public class ServerConnectTask extends AsyncTask {
private Context mContext;
private QRPushToTalkDatabase mDatabase;
@@ -52,8 +31,6 @@ public ServerConnectTask(Context context, QRPushToTalkDatabase database) {
@Override
protected Intent doInBackground(Server... params) {
Server server = params[0];
-
- /* Convert input method defined in settings to an integer format used by Jumble. */
int inputMethod = mSettings.getJumbleInputMethod();
int audioSource = mSettings.isHandsetMode() ?
@@ -70,7 +47,7 @@ protected Intent doInBackground(Server... params) {
Intent connectIntent = new Intent(mContext, QRPushToTalkService.class);
connectIntent.putExtra(JumbleService.EXTRAS_SERVER, server);
- connectIntent.putExtra(JumbleService.EXTRAS_CLIENT_NAME, mContext.getString(R.string.app_name)+" "+applicationVersion);
+ connectIntent.putExtra(JumbleService.EXTRAS_CLIENT_NAME, mContext.getString(R.string.app_name) + " " + applicationVersion);
connectIntent.putExtra(JumbleService.EXTRAS_TRANSMIT_MODE, inputMethod);
connectIntent.putExtra(JumbleService.EXTRAS_DETECTION_THRESHOLD, mSettings.getDetectionThreshold());
connectIntent.putExtra(JumbleService.EXTRAS_AMPLITUDE_BOOST, mSettings.getAmplitudeBoostMultiplier());
diff --git a/app/src/main/java/com/terracom/qrpttbeta/channel/AccessTokenFragment.java b/app/src/main/java/com/terracom/qrpttbeta/channel/AccessTokenFragment.java
deleted file mode 100644
index bf09861f..00000000
--- a/app/src/main/java/com/terracom/qrpttbeta/channel/AccessTokenFragment.java
+++ /dev/null
@@ -1,178 +0,0 @@
-/*
- * Copyright (C) 2014 Andrew Comminos
- *
- * This program 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 .
- */
-
-package com.terracom.qrpttbeta.channel;
-
-import android.app.Activity;
-import android.content.Context;
-import android.os.Bundle;
-import android.os.RemoteException;
-import android.util.Log;
-import android.view.KeyEvent;
-import android.view.LayoutInflater;
-import android.view.View;
-import android.view.View.OnClickListener;
-import android.view.ViewGroup;
-import android.view.inputmethod.EditorInfo;
-import android.widget.ArrayAdapter;
-import android.widget.EditText;
-import android.widget.ImageButton;
-import android.widget.ListView;
-import android.widget.TextView;
-import android.widget.TextView.OnEditorActionListener;
-
-import com.terracom.qrpttbeta.Constants;
-import com.terracom.qrpttbeta.R;
-import com.terracom.qrpttbeta.db.DatabaseProvider;
-import com.terracom.qrpttbeta.util.JumbleServiceFragment;
-
-import java.util.ArrayList;
-import java.util.List;
-
-public class AccessTokenFragment extends JumbleServiceFragment {
-
- public interface AccessTokenListener {
- public void onAccessTokenAdded(long serverId, String token);
- public void onAccessTokenRemoved(long serverId, String token);
- }
-
- private List mTokens;
-
- private ListView mTokenList;
- private TokenAdapter mTokenAdapter;
- private EditText mTokenField;
-
- private DatabaseProvider mProvider;
-
- @Override
- public void onAttach(Activity activity) {
- super.onAttach(activity);
-
- mTokens = new ArrayList(getAccessTokens());
- mTokenAdapter = new TokenAdapter(activity, mTokens);
-
- try {
- mProvider = (DatabaseProvider) activity;
- } catch (ClassCastException e) {
- throw new ClassCastException(activity.toString() + " must implement DatabaseProvider");
- }
- }
-
- @Override
- public View onCreateView(LayoutInflater inflater, ViewGroup container,
- Bundle savedInstanceState) {
- View view = inflater.inflate(R.layout.fragment_tokens, container, false);
-
- mTokenList = (ListView) view.findViewById(R.id.tokenList);
- mTokenList.setAdapter(mTokenAdapter);
-
- mTokenField = (EditText) view.findViewById(R.id.tokenField);
- mTokenField.setOnEditorActionListener(new OnEditorActionListener() {
-
- @Override
- public boolean onEditorAction(TextView v, int actionId, KeyEvent event) {
- if(actionId == EditorInfo.IME_ACTION_SEND) {
- addToken();
- return true;
- }
- return false;
- }
- });
-
- ImageButton addButton = (ImageButton) view.findViewById(R.id.tokenAddButton);
- addButton.setOnClickListener(new OnClickListener() {
-
- @Override
- public void onClick(View v) {
- addToken();
- }
- });
-
- return view;
- }
-
- private void addToken() {
- String tokenText = mTokenField.getText().toString().trim();
-
- if(tokenText.equals(""))
- return;
-
- mTokenField.setText("");
-
- Log.i(Constants.TAG, "Adding token: "+tokenText);
-
- mTokens.add(tokenText);
- mTokenAdapter.notifyDataSetChanged();
-
- mTokenList.smoothScrollToPosition(mTokens.size() - 1);
- mProvider.getDatabase().addAccessToken(getServerId(), tokenText);
- try {
- getService().sendAccessTokens(mTokens);
- } catch (RemoteException e) {
- e.printStackTrace();
- }
- }
-
- private long getServerId() {
- return getArguments().getLong("server");
- }
-
- private List getAccessTokens() {
- return getArguments().getStringArrayList("access_tokens");
- }
-
- private class TokenAdapter extends ArrayAdapter {
-
- public TokenAdapter(Context context,
- List objects) {
- super(context, android.R.layout.simple_list_item_1, objects);
- }
-
- @Override
- public View getView(final int position, View convertView, ViewGroup parent) {
- View view = convertView;
- if(convertView == null) {
- view = getActivity().getLayoutInflater().inflate(R.layout.token_row, null, false);
- }
-
- final String token = getItem(position);
-
- TextView title = (TextView) view.findViewById(R.id.tokenItemTitle);
- title.setText(token);
-
- ImageButton deleteButton = (ImageButton) view.findViewById(R.id.tokenItemDelete);
- deleteButton.setOnClickListener(new OnClickListener() {
-
- @Override
- public void onClick(View v) {
- mTokens.remove(position);
- notifyDataSetChanged();
- mProvider.getDatabase().removeAccessToken(getServerId(), token);
- try {
- getService().sendAccessTokens(mTokens);
- } catch (RemoteException e) {
- e.printStackTrace();
- }
- }
- });
-
- return view;
- }
-
- }
-
-}
diff --git a/app/src/main/java/com/terracom/qrpttbeta/channel/ChannelAdapter.java b/app/src/main/java/com/terracom/qrpttbeta/channel/ChannelAdapter.java
old mode 100644
new mode 100755
index f29b9f07..b3d42660
--- a/app/src/main/java/com/terracom/qrpttbeta/channel/ChannelAdapter.java
+++ b/app/src/main/java/com/terracom/qrpttbeta/channel/ChannelAdapter.java
@@ -1,20 +1,3 @@
-/*
- * Copyright (C) 2014 Andrew Comminos
- *
- * This program 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 .
- */
-
package com.terracom.qrpttbeta.channel;
import android.content.Context;
@@ -31,10 +14,6 @@
import com.terracom.jumble.model.User;
import com.terracom.qrpttbeta.R;
-/**
- * Simple adapter to display the users in a single channel.
- * Created by andrew on 24/11/13.
- */
public class ChannelAdapter extends BaseAdapter {
private Context mContext;
@@ -70,7 +49,7 @@ public long getItemId(int position) {
@Override
public View getView(int position, View convertView, ViewGroup parent) {
View v = convertView;
- if(v == null) {
+ if (v == null) {
LayoutInflater layoutInflater = LayoutInflater.from(mContext);
v = layoutInflater.inflate(R.layout.overlay_user_row, parent, false);
}
@@ -89,8 +68,7 @@ else if (user.isMuted())
state.setImageResource(R.drawable.ic_server_muted);
else if (user.isSuppressed())
state.setImageResource(R.drawable.ic_suppressed);
- else
- if (user.getTalkState() == User.TalkState.TALKING)
+ else if (user.getTalkState() == User.TalkState.TALKING)
state.setImageResource(R.drawable.ic_talking_on);
else
state.setImageResource(R.drawable.ic_talking_off);
diff --git a/app/src/main/java/com/terracom/qrpttbeta/channel/ChannelChatFragment.java b/app/src/main/java/com/terracom/qrpttbeta/channel/ChannelChatFragment.java
old mode 100644
new mode 100755
index 656b70f7..1ff84faf
--- a/app/src/main/java/com/terracom/qrpttbeta/channel/ChannelChatFragment.java
+++ b/app/src/main/java/com/terracom/qrpttbeta/channel/ChannelChatFragment.java
@@ -1,20 +1,3 @@
-/*
- * Copyright (C) 2014 Andrew Comminos
- *
- * This program 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 .
- */
-
package com.terracom.qrpttbeta.channel;
import android.app.Activity;
@@ -61,7 +44,7 @@ public class ChannelChatFragment extends JumbleServiceFragment implements ChatTa
private static final Pattern LINK_PATTERN = Pattern.compile("(https?://\\S+)");
private static final String CHAT_DATE_FORMAT = "%I:%M %p";
- private IJumbleObserver mServiceObserver = new JumbleObserver() {
+ private IJumbleObserver mServiceObserver = new JumbleObserver() {
@Override
public void onMessageLogged(Message message) throws RemoteException {
@@ -73,7 +56,6 @@ public void onUserJoinedChannel(User user, Channel newChannel, Channel oldChanne
if (user != null && getService().getSessionUser() != null &&
user.equals(getService().getSessionUser()) &&
mTargetProvider.getChatTarget() == null) {
- // Update chat target when user changes channels without a target.
updateChatTargetText(null);
}
}
@@ -81,8 +63,8 @@ public void onUserJoinedChannel(User user, Channel newChannel, Channel oldChanne
private ListView mChatList;
private ChannelChatAdapter mChatAdapter;
- private EditText mChatTextEdit;
- private ImageButton mSendButton;
+ private EditText mChatTextEdit;
+ private ImageButton mSendButton;
private ChatTargetProvider mTargetProvider;
@Override
@@ -97,7 +79,7 @@ public void onAttach(Activity activity) {
try {
mTargetProvider = (ChatTargetProvider) getParentFragment();
} catch (ClassCastException e) {
- throw new ClassCastException(getParentFragment().toString()+" must implement ChatTargetProvider");
+ throw new ClassCastException(getParentFragment().toString() + " must implement ChatTargetProvider");
}
}
@@ -114,14 +96,14 @@ public void onPause() {
}
@Override
- public View onCreateView(LayoutInflater inflater, ViewGroup container,
- Bundle savedInstanceState) {
- View view = inflater.inflate(R.layout.fragment_chat, container, false);
+ public View onCreateView(LayoutInflater inflater, ViewGroup container,
+ Bundle savedInstanceState) {
+ View view = inflater.inflate(R.layout.fragment_chat, container, false);
mChatList = (ListView) view.findViewById(R.id.chat_list);
- mChatTextEdit = (EditText) view.findViewById(R.id.chatTextEdit);
-
- mSendButton = (ImageButton) view.findViewById(R.id.chatTextSend);
- mSendButton.setOnClickListener(new OnClickListener() {
+ mChatTextEdit = (EditText) view.findViewById(R.id.chatTextEdit);
+
+ mSendButton = (ImageButton) view.findViewById(R.id.chatTextSend);
+ mSendButton.setOnClickListener(new OnClickListener() {
@Override
public void onClick(View v) {
try {
@@ -131,8 +113,8 @@ public void onClick(View v) {
}
}
});
-
- mChatTextEdit.setOnEditorActionListener(new OnEditorActionListener() {
+
+ mChatTextEdit.setOnEditorActionListener(new OnEditorActionListener() {
@Override
public boolean onEditorAction(TextView v, int actionId, KeyEvent event) {
try {
@@ -143,8 +125,8 @@ public boolean onEditorAction(TextView v, int actionId, KeyEvent event) {
return true;
}
});
-
- mChatTextEdit.addTextChangedListener(new TextWatcher() {
+
+ mChatTextEdit.addTextChangedListener(new TextWatcher() {
@Override
public void onTextChanged(CharSequence s, int start, int before, int count) {
@@ -167,7 +149,7 @@ public void afterTextChanged(Editable s) {
e.printStackTrace();
}
return view;
- }
+ }
@Override
public void onCreateOptionsMenu(Menu menu, MenuInflater inflater) {
@@ -184,17 +166,12 @@ public boolean onOptionsItemSelected(MenuItem item) {
return super.onOptionsItemSelected(item);
}
- /**
- * Adds the passed text to the fragment chat body.
- * @param message The message to add.
- * @param scroll Whether to scroll to the bottom after adding the message.
- */
public void addChatMessage(Message message, boolean scroll) {
- if(mChatAdapter == null) return;
+ if (mChatAdapter == null) return;
mChatAdapter.add(message);
- if(scroll) {
+ if (scroll) {
mChatList.post(new Runnable() {
@Override
@@ -203,34 +180,24 @@ public void run() {
}
});
}
- }
-
- /**
- * Sends the message currently in {@link com.terracom.qrpttbeta.channel.ChannelChatFragment#mChatTextEdit}
- * to the remote server. Clears the message box if the message was sent successfully.
- * @throws RemoteException If the service failed to send the message.
- */
- private void sendMessage() throws RemoteException {
- if(mChatTextEdit.length() == 0) return;
+ }
+
+ private void sendMessage() throws RemoteException {
+ if (mChatTextEdit.length() == 0) return;
String message = mChatTextEdit.getText().toString();
String formattedMessage = markupOutgoingMessage(message);
ChatTargetProvider.ChatTarget target = mTargetProvider.getChatTarget();
Message responseMessage = null;
- if(target == null)
+ if (target == null)
responseMessage = getService().sendChannelTextMessage(getService().getSessionChannel().getId(), formattedMessage, false);
- else if(target.getUser() != null)
+ else if (target.getUser() != null)
responseMessage = getService().sendUserTextMessage(target.getUser().getSession(), formattedMessage);
- else if(target.getChannel() != null)
+ else if (target.getChannel() != null)
responseMessage = getService().sendChannelTextMessage(target.getChannel().getId(), formattedMessage, false);
addChatMessage(responseMessage, true);
mChatTextEdit.setText("");
- }
+ }
- /**
- * Adds HTML markup to the message, replacing links and newlines.
- * @param message The message to markup.
- * @return HTML data.
- */
private String markupOutgoingMessage(String message) {
String formattedBody = message;
Matcher matcher = LINK_PATTERN.matcher(formattedBody);
@@ -238,8 +205,8 @@ private String markupOutgoingMessage(String message) {
.replaceAll("\n", " ");
return formattedBody;
}
-
- public void clear() {
+
+ public void clear() {
mChatAdapter.clear();
try {
getService().clearMessageLog();
@@ -248,23 +215,20 @@ public void clear() {
}
}
- /**
- * Updates hint displaying chat target.
- */
- public void updateChatTargetText(ChatTargetProvider.ChatTarget target) throws RemoteException {
- if(getService() == null) return;
+ public void updateChatTargetText(ChatTargetProvider.ChatTarget target) throws RemoteException {
+ if (getService() == null) return;
String hint = null;
- if(target == null && getService().getSessionChannel() != null) {
+ if (target == null && getService().getSessionChannel() != null) {
hint = getString(R.string.messageToChannel, getService().getSessionChannel().getName());
- } else if(target != null && target.getUser() != null) {
+ } else if (target != null && target.getUser() != null) {
hint = getString(R.string.messageToUser, target.getUser().getName());
- } else if(target != null && target.getChannel() != null) {
+ } else if (target != null && target.getChannel() != null) {
hint = getString(R.string.messageToChannel, target.getChannel().getName());
}
mChatTextEdit.setHint(hint);
- mChatTextEdit.requestLayout(); // Needed to update bounds after hint change.
- }
+ mChatTextEdit.requestLayout();
+ }
@Override
@@ -311,7 +275,7 @@ public ChannelChatAdapter(Context context, IJumbleService service, List
@Override
public View getView(int position, View convertView, ViewGroup parent) {
View v = convertView;
- if(v == null) {
+ if (v == null) {
v = LayoutInflater.from(getContext()).inflate(R.layout.list_chat_item, parent, false);
}
@@ -368,7 +332,7 @@ public boolean areAllItemsEnabled() {
@Override
public boolean isEnabled(int position) {
- return false; // Makes links clickable.
+ return false;
}
}
}
diff --git a/app/src/main/java/com/terracom/qrpttbeta/channel/ChannelEditFragment.java b/app/src/main/java/com/terracom/qrpttbeta/channel/ChannelEditFragment.java
old mode 100644
new mode 100755
index da212b63..bc717387
--- a/app/src/main/java/com/terracom/qrpttbeta/channel/ChannelEditFragment.java
+++ b/app/src/main/java/com/terracom/qrpttbeta/channel/ChannelEditFragment.java
@@ -1,20 +1,3 @@
-/*
- * Copyright (C) 2014 Andrew Comminos
- *
- * This program 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 .
- */
-
package com.terracom.qrpttbeta.channel;
import android.app.Activity;
@@ -34,9 +17,6 @@
import com.terracom.qrpttbeta.R;
import com.terracom.qrpttbeta.util.JumbleServiceProvider;
-/**
- * Created by andrew on 23/11/13.
- */
public class ChannelEditFragment extends DialogFragment {
private JumbleServiceProvider mServiceProvider;
@@ -66,7 +46,6 @@ public Dialog onCreateDialog(Bundle savedInstanceState) {
mTemporaryBox = (CheckBox) view.findViewById(R.id.channel_edit_temporary);
try {
- // If we can only make temporary channels, remove the option.
Channel parentChannel = mServiceProvider.getService().getChannel(getParent());
int combinedPermissions = mServiceProvider.getService().getPermissions() | parentChannel.getPermissions();
boolean canMakeChannel = (combinedPermissions & Permissions.MakeChannel) > 0;
@@ -85,7 +64,7 @@ public Dialog onCreateDialog(Bundle savedInstanceState) {
@Override
public void onClick(DialogInterface dialog, int which) {
try {
- if(isAdding()) {
+ if (isAdding()) {
mServiceProvider.getService().createChannel(getParent(),
mNameField.getText().toString(),
mDescriptionField.getText().toString(),
@@ -103,22 +82,14 @@ public void onClick(DialogInterface dialog, int which) {
.create();
}
- /**
- * @return true if the user is adding a new channel.
- */
public boolean isAdding() {
return getArguments().getBoolean("adding");
}
- /**
- * @return the parent channel that the new channel will be a child of.
- */
public int getParent() {
return getArguments().getInt("parent");
}
- /**
- * @return the channel being updated.
- */
+
public int getChannel() {
return getArguments().getInt("channel");
}
diff --git a/app/src/main/java/com/terracom/qrpttbeta/channel/ChannelFragment.java b/app/src/main/java/com/terracom/qrpttbeta/channel/ChannelFragment.java
old mode 100644
new mode 100755
index 86ff3b1c..db145b63
--- a/app/src/main/java/com/terracom/qrpttbeta/channel/ChannelFragment.java
+++ b/app/src/main/java/com/terracom/qrpttbeta/channel/ChannelFragment.java
@@ -1,20 +1,3 @@
-/*
- * Copyright (C) 2014 Andrew Comminos
- *
- * This program 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 .
- */
-
package com.terracom.qrpttbeta.channel;
import android.content.SharedPreferences;
@@ -47,10 +30,6 @@
import java.util.ArrayList;
import java.util.List;
-/**
- * Class to encapsulate both a ChannelListFragment and ChannelChatFragment.
- * Created by andrew on 02/08/13.
- */
public class ChannelFragment extends JumbleServiceFragment implements SharedPreferences.OnSharedPreferenceChangeListener, ChatTargetProvider {
private ViewPager mViewPager;
@@ -59,7 +38,6 @@ public class ChannelFragment extends JumbleServiceFragment implements SharedPref
private View mTalkView;
private ChatTarget mChatTarget;
- /** Chat target listeners, notified when the chat target is changed. */
private List mChatTargetListeners = new ArrayList();
private boolean mTogglePTT;
@@ -67,8 +45,6 @@ public class ChannelFragment extends JumbleServiceFragment implements SharedPref
@Override
public void onUserTalkStateUpdated(User user) throws RemoteException {
if (user != null && user.getSession() == getService().getSession()) {
- // Manually set button selection colour when we receive a talk state update.
- // This allows representation of talk state when using hot corners and PTT toggle.
switch (user.getTalkState()) {
case TALKING:
case SHOUTING:
@@ -94,8 +70,8 @@ public View onCreateView(LayoutInflater inflater, ViewGroup container, Bundle sa
View view = inflater.inflate(R.layout.fragment_channel, container, false);
mViewPager = (ViewPager) view.findViewById(R.id.channel_view_pager);
mTabStrip = (PagerTabStrip) view.findViewById(R.id.channel_tab_strip);
- if(mTabStrip != null) {
- int[] attrs = new int[] { R.attr.colorPrimary, android.R.attr.textColorPrimaryInverse };
+ if (mTabStrip != null) {
+ int[] attrs = new int[]{R.attr.colorPrimary, android.R.attr.textColorPrimaryInverse};
TypedArray a = getActivity().obtainStyledAttributes(attrs);
int titleStripBackground = a.getColor(0, -1);
int titleStripColor = a.getColor(1, -1);
@@ -144,10 +120,10 @@ public void onActivityCreated(Bundle savedInstanceState) {
SharedPreferences preferences = PreferenceManager.getDefaultSharedPreferences(getActivity());
preferences.registerOnSharedPreferenceChangeListener(this);
- if(mViewPager != null) { // Phone
+ if (mViewPager != null) {
ChannelFragmentPagerAdapter pagerAdapter = new ChannelFragmentPagerAdapter(getChildFragmentManager());
mViewPager.setAdapter(pagerAdapter);
- } else { // Tablet
+ } else {
ChannelListFragment listFragment = new ChannelListFragment();
Bundle listArgs = new Bundle();
listArgs.putBoolean("pinned", isShowingPinnedChannels());
@@ -164,7 +140,6 @@ public void onActivityCreated(Bundle savedInstanceState) {
@Override
public void onCreateOptionsMenu(Menu menu, MenuInflater inflater) {
super.onCreateOptionsMenu(menu, inflater);
-// inflater.inflate(R.menu.channel_menu, menu);
}
@Override
@@ -196,17 +171,11 @@ public IJumbleObserver getServiceObserver() {
return mObserver;
}
- /**
- * @return true if the channel fragment is set to display only the user's pinned channels.
- */
private boolean isShowingPinnedChannels() {
return getArguments() != null &&
- getArguments().getBoolean("pinned");
+ getArguments().getBoolean("pinned");
}
- /**
- * Configures the fragment in accordance with the user's interface preferences.
- */
private void configureInput() {
Settings settings = Settings.getInstance(getActivity());
boolean showPttButton = settings.isPushToTalkButtonShown() && settings.getInputMethod().equals(Settings.ARRAY_INPUT_METHOD_PTT);
@@ -216,7 +185,7 @@ private void configureInput() {
@Override
public void onSharedPreferenceChanged(SharedPreferences sharedPreferences, String key) {
- if(Settings.PREF_INPUT_METHOD.equals(key) ||
+ if (Settings.PREF_INPUT_METHOD.equals(key) ||
Settings.PREF_PUSH_BUTTON_HIDE_KEY.equals(key) ||
Settings.PREF_PTT_TOGGLE.equals(key))
configureInput();
@@ -230,7 +199,7 @@ public ChatTarget getChatTarget() {
@Override
public void setChatTarget(ChatTarget target) {
mChatTarget = target;
- for(OnChatTargetSelectedListener listener : mChatTargetListeners)
+ for (OnChatTargetSelectedListener listener : mChatTargetListeners)
listener.onChatTargetSelected(target);
}
diff --git a/app/src/main/java/com/terracom/qrpttbeta/channel/ChannelListAdapter.java b/app/src/main/java/com/terracom/qrpttbeta/channel/ChannelListAdapter.java
old mode 100644
new mode 100755
index 5e3b5696..e364d4f7
--- a/app/src/main/java/com/terracom/qrpttbeta/channel/ChannelListAdapter.java
+++ b/app/src/main/java/com/terracom/qrpttbeta/channel/ChannelListAdapter.java
@@ -1,20 +1,3 @@
-/*
- * Copyright (C) 2014 Andrew Comminos
- *
- * This program 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 .
- */
-
package com.terracom.qrpttbeta.channel;
import android.content.Context;
@@ -48,18 +31,11 @@
import java.util.LinkedList;
import java.util.List;
-/**
- * Created by andrew on 31/07/13.
- */
public class ChannelListAdapter extends RecyclerView.Adapter {
- // Set particular bits to make the integer-based model item ids unique.
public static final long CHANNEL_ID_MASK = (0x1L << 32);
public static final long USER_ID_MASK = (0x1L << 33);
String nameOfChannel = QRPushToTalkActivity.nameOfSavedLastLoggedChannel;
- /**
- * Time (in ms) to run the flip animation for.
- */
private static final long FLIP_DURATION = 350;
private Context mContext;
@@ -67,10 +43,6 @@ public class ChannelListAdapter extends RecyclerView.Adapter {
private QRPushToTalkDatabase mDatabase;
private List mRootChannels;
private List mNodes;
- /**
- * A mapping of user-set channel expansions.
- * If a key is not mapped, default to hiding empty channels.
- */
private HashMap mExpandedChannels;
private OnUserClickListener mUserClickListener;
private OnChannelClickListener mChannelClickListener;
@@ -82,13 +54,12 @@ public ChannelListAdapter(Context context, IJumbleService service, QRPushToTalkD
mDatabase = database;
mRootChannels = new ArrayList();
- if(showPinnedOnly) {
+ if (showPinnedOnly) {
mRootChannels = mDatabase.getPinnedChannels(mService.getConnectedServer().getId());
} else {
mRootChannels.add(0);
}
- // Construct channel tree
mNodes = new LinkedList();
mExpandedChannels = new HashMap();
updateChannels();
@@ -111,8 +82,8 @@ public RecyclerView.ViewHolder onCreateViewHolder(ViewGroup viewGroup, int viewT
public void onBindViewHolder(RecyclerView.ViewHolder viewHolder, int position) {
final Node node = mNodes.get(position);
- if(!nameOfChannel.equals("")){
- if(node.isChannel() && !node.getChannel().getName().equals(nameOfChannel) && !node.getChannel().getName().equals("QR-PushToTalk Server")){
+ if (!nameOfChannel.equals("")) {
+ if (node.isChannel() && !node.getChannel().getName().equals(nameOfChannel) && !node.getChannel().getName().equals("QR-PushToTalk Server")) {
try {
updateChannels(); // FIXME: very inefficient.
@@ -133,7 +104,7 @@ public void onBindViewHolder(RecyclerView.ViewHolder viewHolder, int position) {
e.printStackTrace();
}
- } else if(node.isUser() && !node.getParent().getChannel().getName().equals(nameOfChannel)){
+ } else if (node.isUser() && !node.getParent().getChannel().getName().equals(nameOfChannel)) {
try {
updateChannels(); // FIXME: very inefficient.
@@ -148,18 +119,16 @@ public void onBindViewHolder(RecyclerView.ViewHolder viewHolder, int position) {
uvh.mUserHolder.setVisibility(View.GONE);
uvh.itemView.setVisibility(View.GONE);
- // Pad the view depending on channel's nested level.
DisplayMetrics metrics = mContext.getResources().getDisplayMetrics();
float margin = (node.getDepth() + 1) * TypedValue.applyDimension(TypedValue.COMPLEX_UNIT_DIP, 25, metrics);
- uvh.mUserHolder.setPadding((int) margin,0,uvh.mUserHolder.getPaddingRight(),0);
+ uvh.mUserHolder.setPadding((int) margin, 0, uvh.mUserHolder.getPaddingRight(), 0);
try {
updateChannels(); // FIXME: very inefficient.
} catch (RemoteException e) {
e.printStackTrace();
}
- }
- else if (node.isChannel() ) {
+ } else if (node.isChannel()) {
final Channel channel = node.getChannel();
ChannelViewHolder cvh = (ChannelViewHolder) viewHolder;
cvh.itemView.setOnClickListener(new View.OnClickListener() {
@@ -188,20 +157,18 @@ public void onClick(View v) {
notifyDataSetChanged();
}
});
- // Dim channel expand toggle when no subchannels exist
cvh.mChannelExpandToggle.setEnabled(expandUsable);
cvh.mChannelExpandToggle.setVisibility(expandUsable ? View.VISIBLE : View.INVISIBLE);
cvh.mChannelName.setText(channel.getName());
int userCount = channel.getSubchannelUserCount();
- if(node.getChannel().getName().equals("QR-PushToTalk Server"))
+ if (node.getChannel().getName().equals("QR-PushToTalk Server"))
cvh.mChannelUserCount.setText("");
- else{
+ else {
cvh.mChannelUserCount.setText(String.format("%d", userCount));
}
- // Pad the view depending on channel's nested level.
DisplayMetrics metrics = mContext.getResources().getDisplayMetrics();
float margin = node.getDepth() * TypedValue.applyDimension(TypedValue.COMPLEX_UNIT_DIP, 25, metrics);
cvh.mChannelHolder.setPadding((int) margin,
@@ -239,7 +206,6 @@ public void onClick(View v) {
uvh.mUserTalkHighlight.setImageDrawable(getTalkStateDrawable(user));
- // Pad the view depending on channel's nested level.
DisplayMetrics metrics = mContext.getResources().getDisplayMetrics();
float margin = (node.getDepth() + 1) * TypedValue.applyDimension(TypedValue.COMPLEX_UNIT_DIP, 25, metrics);
uvh.mUserHolder.setPadding((int) margin,
@@ -252,8 +218,8 @@ public void onClick(View v) {
e.printStackTrace();
}
}
- }else{
- if(node.isChannel() && !node.getChannel().getName().equals("Demo Channel") && !node.getChannel().getName().equals("QR-PushToTalk Server")){
+ } else {
+ if (node.isChannel() && !node.getChannel().getName().equals("Demo Channel") && !node.getChannel().getName().equals("QR-PushToTalk Server")) {
ChannelViewHolder cvh = (ChannelViewHolder) viewHolder;
cvh.mChannelExpandToggle.setVisibility(View.GONE);
cvh.mChannelName.setText("");
@@ -268,7 +234,7 @@ public void onClick(View v) {
e.printStackTrace();
}
- } else if(node.isUser() && !node.getParent().getChannel().getName().equals("Demo Channel")){
+ } else if (node.isUser() && !node.getParent().getChannel().getName().equals("Demo Channel")) {
UserViewHolder uvh = (UserViewHolder) viewHolder;
uvh.mUserName.setText("");
uvh.mUserName.setVisibility(View.GONE);
@@ -277,7 +243,6 @@ public void onClick(View v) {
uvh.mUserHolder.setVisibility(View.GONE);
uvh.itemView.setVisibility(View.GONE);
- // Pad the view depending on channel's nested level.
DisplayMetrics metrics = mContext.getResources().getDisplayMetrics();
float margin = (node.getDepth() + 1) * TypedValue.applyDimension(TypedValue.COMPLEX_UNIT_DIP, 25, metrics);
uvh.mUserHolder.setPadding((int) margin,
@@ -289,8 +254,7 @@ public void onClick(View v) {
} catch (RemoteException e) {
e.printStackTrace();
}
- }
- else if (node.isChannel()) {
+ } else if (node.isChannel()) {
final Channel channel = node.getChannel();
ChannelViewHolder cvh = (ChannelViewHolder) viewHolder;
cvh.itemView.setOnClickListener(new View.OnClickListener() {
@@ -319,21 +283,19 @@ public void onClick(View v) {
notifyDataSetChanged();
}
});
- // Dim channel expand toggle when no subchannels exist
+
cvh.mChannelExpandToggle.setEnabled(expandUsable);
cvh.mChannelExpandToggle.setVisibility(expandUsable ? View.VISIBLE : View.INVISIBLE);
cvh.mChannelName.setText(channel.getName());
int userCount = channel.getSubchannelUserCount();
- if(node.getChannel().getName().equals("QR-PushToTalk Server"))
+ if (node.getChannel().getName().equals("QR-PushToTalk Server"))
cvh.mChannelUserCount.setText("");
- else{
+ else {
cvh.mChannelUserCount.setText(String.format("%d", userCount));
}
-
- // Pad the view depending on channel's nested level.
DisplayMetrics metrics = mContext.getResources().getDisplayMetrics();
float margin = node.getDepth() * TypedValue.applyDimension(TypedValue.COMPLEX_UNIT_DIP, 25, metrics);
cvh.mChannelHolder.setPadding((int) margin,
@@ -345,7 +307,7 @@ public void onClick(View v) {
} catch (RemoteException e) {
e.printStackTrace();
}
- } else if (node.isUser() ) {
+ } else if (node.isUser()) {
final User user = node.getUser();
UserViewHolder uvh = (UserViewHolder) viewHolder;
uvh.itemView.setOnClickListener(new View.OnClickListener() {
@@ -366,7 +328,6 @@ public void onClick(View v) {
uvh.mUserTalkHighlight.setImageDrawable(getTalkStateDrawable(user));
- // Pad the view depending on channel's nested level.
DisplayMetrics metrics = mContext.getResources().getDisplayMetrics();
float margin = (node.getDepth() + 1) * TypedValue.applyDimension(TypedValue.COMPLEX_UNIT_DIP, 25, metrics);
uvh.mUserHolder.setPadding((int) margin,
@@ -407,10 +368,6 @@ public long getItemId(int position) {
return mNodes.get(position).getId();
}
- /**
- * Updates the channel tree model.
- * To be used after any channel tree modifications.
- */
public void updateChannels() throws RemoteException {
mNodes.clear();
for (int cid : mRootChannels) {
@@ -421,11 +378,6 @@ public void updateChannels() throws RemoteException {
}
}
- /**
- * Updates the user's state icon with a nice animation.
- * @param user The user to update.
- * @param view The view containing this adapter.
- */
public void animateUserStateUpdate(User user, RecyclerView view) {
long itemId = user.getSession() | USER_ID_MASK;
UserViewHolder uvh = (UserViewHolder) view.findViewHolderForItemId(itemId);
@@ -435,12 +387,10 @@ public void animateUserStateUpdate(User user, RecyclerView view) {
if (!newState.getConstantState().equals(oldState.getConstantState())) {
if (Build.VERSION.SDK_INT >= 12) {
- // "Flip" in new talking state.
FlipDrawable drawable = new FlipDrawable(oldState, newState);
uvh.mUserTalkHighlight.setImageDrawable(drawable);
drawable.start(FLIP_DURATION);
} else {
- // If we're on a platform without ValueAnimator, simply set the state image.
uvh.mUserTalkHighlight.setImageDrawable(newState);
}
}
@@ -465,7 +415,6 @@ private Drawable getTalkStateDrawable(User user) {
// TODO: add whisper and shouting resources
return resources.getDrawable(R.drawable.outline_circle_talking_on);
} else {
- // Passive drawables
if (user.getTexture() != null) {
return new CircleDrawable(mContext.getResources(), user.getTexture());
} else {
@@ -504,13 +453,6 @@ public void setOnChannelClickListener(OnChannelClickListener listener) {
mChannelClickListener = listener;
}
- /**
- * Recursively creates a list of {@link Node}s representing the channel hierarchy.
- * @param parent The parent node to propagate under.
- * @param channel The parent channel.
- * @param depth The current depth of the subtree.
- * @param nodes An accumulator to store generated nodes into.
- */
private void constructNodes(Node parent, Channel channel, int depth,
List nodes) throws RemoteException {
Node channelNode = new Node(parent, depth, channel);
@@ -520,7 +462,7 @@ private void constructNodes(Node parent, Channel channel, int depth,
if ((expandSetting == null && channel.getSubchannelUserCount() == 0)
|| (expandSetting != null && !expandSetting)) {
channelNode.setExpanded(false);
- return; // Skip adding children of contracted/empty channels.
+ return;
}
for (int uid : channel.getUsers()) {
@@ -536,11 +478,6 @@ private void constructNodes(Node parent, Channel channel, int depth,
}
}
- /**
- * Changes the service backing the adapter. Updates the list as well.
- * @param service The new service to retrieve channels from.
- * @throws RemoteException
- */
public void setService(IJumbleService service) throws RemoteException {
mService = service;
updateChannels();
@@ -551,7 +488,6 @@ private static class UserViewHolder extends RecyclerView.ViewHolder {
public LinearLayout mUserHolder;
public TextView mUserName;
public FrameLayout mPicofMic;
-// public ImageView mUserAvatar;
public ImageView mUserTalkHighlight;
public UserViewHolder(View itemView) {
@@ -579,10 +515,6 @@ public ChannelViewHolder(View itemView) {
}
}
- /**
- * An arbitrary node in the channel-user hierarchy.
- * Can be either a channel or user.
- */
private static class Node {
private Node mParent;
private Channel mChannel;
@@ -616,7 +548,7 @@ public Node getParent() {
}
public Channel getChannel() {
- return mChannel;
+ return mChannel;
}
public User getUser() {
@@ -624,7 +556,6 @@ public User getUser() {
}
public Long getId() {
- // Apply flags to differentiate integer-length identifiers
if (isChannel()) {
return CHANNEL_ID_MASK | mChannel.getId();
} else if (isUser()) {
diff --git a/app/src/main/java/com/terracom/qrpttbeta/channel/ChannelListFragment.java b/app/src/main/java/com/terracom/qrpttbeta/channel/ChannelListFragment.java
old mode 100644
new mode 100755
index c8bee4b9..a50af0e5
--- a/app/src/main/java/com/terracom/qrpttbeta/channel/ChannelListFragment.java
+++ b/app/src/main/java/com/terracom/qrpttbeta/channel/ChannelListFragment.java
@@ -1,31 +1,10 @@
-/*
- * Copyright (C) 2014 Andrew Comminos
- *
- * This program 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 .
- */
-
package com.terracom.qrpttbeta.channel;
import android.app.Activity;
import android.app.SearchManager;
-import android.content.BroadcastReceiver;
import android.content.Context;
-import android.content.Intent;
-import android.content.IntentFilter;
import android.database.CursorWrapper;
-import android.graphics.PorterDuff;
-import android.media.AudioManager;
+import android.graphics.PorterDuff;;
import android.os.Bundle;
import android.os.RemoteException;
import android.support.v4.view.MenuItemCompat;
@@ -58,7 +37,7 @@
public class ChannelListFragment extends JumbleServiceFragment implements UserActionModeCallback.LocalUserUpdateListener, OnChannelClickListener, OnUserClickListener {
- private IJumbleObserver mServiceObserver = new JumbleObserver() {
+ private IJumbleObserver mServiceObserver = new JumbleObserver() {
@Override
public void onDisconnected(JumbleException e) throws RemoteException {
mChannelView.setAdapter(null);
@@ -68,22 +47,22 @@ public void onDisconnected(JumbleException e) throws RemoteException {
public void onUserJoinedChannel(User user, Channel newChannel, Channel oldChannel) throws RemoteException {
mChannelListAdapter.updateChannels();
mChannelListAdapter.notifyDataSetChanged();
- if(getService().getSession() == user.getSession()) {
+ if (getService().getSession() == user.getSession()) {
scrollToChannel(newChannel.getId());
}
}
@Override
- public void onChannelAdded(Channel channel) throws RemoteException {
+ public void onChannelAdded(Channel channel) throws RemoteException {
mChannelListAdapter.updateChannels();
- mChannelListAdapter.notifyDataSetChanged();
- }
+ mChannelListAdapter.notifyDataSetChanged();
+ }
- @Override
- public void onChannelRemoved(Channel channel) throws RemoteException {
+ @Override
+ public void onChannelRemoved(Channel channel) throws RemoteException {
mChannelListAdapter.updateChannels();
- mChannelListAdapter.notifyDataSetChanged();
- }
+ mChannelListAdapter.notifyDataSetChanged();
+ }
@Override
public void onChannelStateUpdated(Channel channel) throws RemoteException {
@@ -112,18 +91,10 @@ public void onUserStateUpdated(User user) throws RemoteException {
public void onUserTalkStateUpdated(User user) throws RemoteException {
mChannelListAdapter.animateUserStateUpdate(user, mChannelView);
}
- };
+ };
- /*private BroadcastReceiver mBluetoothReceiver = new BroadcastReceiver() {
- @Override
- public void onReceive(Context context, Intent intent) {
- if(getActivity() != null)
- getActivity().supportInvalidateOptionsMenu(); // Update bluetooth menu item
- }
- };*/
-
- private RecyclerView mChannelView;
- private ChannelListAdapter mChannelListAdapter;
+ private RecyclerView mChannelView;
+ private ChannelListAdapter mChannelListAdapter;
private ChatTargetProvider mTargetProvider;
private DatabaseProvider mDatabaseProvider;
private ActionMode mActionMode;
@@ -140,12 +111,12 @@ public void onAttach(Activity activity) {
try {
mTargetProvider = (ChatTargetProvider) getParentFragment();
} catch (ClassCastException e) {
- throw new ClassCastException(getParentFragment().toString()+" must implement ChatTargetProvider");
+ throw new ClassCastException(getParentFragment().toString() + " must implement ChatTargetProvider");
}
try {
mDatabaseProvider = (DatabaseProvider) getActivity();
} catch (ClassCastException e) {
- throw new ClassCastException(getActivity().toString()+" must implement DatabaseProvider");
+ throw new ClassCastException(getActivity().toString() + " must implement DatabaseProvider");
}
}
@@ -163,15 +134,8 @@ public View onCreateView(LayoutInflater inflater, ViewGroup container,
public void onActivityCreated(Bundle savedInstanceState) {
super.onActivityCreated(savedInstanceState);
registerForContextMenu(mChannelView);
- //getActivity().registerReceiver(mBluetoothReceiver, new IntentFilter(AudioManager.ACTION_SCO_AUDIO_STATE_CHANGED));
}
- /*@Override
- public void onDetach() {
- getActivity().unregisterReceiver(mBluetoothReceiver);
- super.onDetach();
- }*/
-
@Override
public IJumbleObserver getServiceObserver() {
return mServiceObserver;
@@ -198,8 +162,7 @@ public void onPrepareOptionsMenu(Menu menu) {
MenuItem deafenItem = menu.findItem(R.id.menu_deafen_button);
try {
- if(getService() != null && getService().getConnectionState() == JumbleService.STATE_CONNECTED && getService().getSessionUser() != null) {
- // Color the action bar icons to the primary text color of the theme, TODO move this elsewhere
+ if (getService() != null && getService().getConnectionState() == JumbleService.STATE_CONNECTED && getService().getSessionUser() != null) {
int foregroundColor = getActivity().getTheme().obtainStyledAttributes(new int[]{android.R.attr.textColorPrimaryInverse}).getColor(0, -1);
User self = getService().getSessionUser();
@@ -211,15 +174,6 @@ public void onPrepareOptionsMenu(Menu menu) {
} catch (RemoteException e) {
e.printStackTrace();
}
-
- /*try {
- if(getService() != null) {
- MenuItem bluetoothItem = menu.findItem(R.id.menu_bluetooth);
- bluetoothItem.setChecked(getService().isBluetoothAvailable());
- }
- } catch (RemoteException e) {
- e.printStackTrace();
- }*/
}
@Override
@@ -229,7 +183,7 @@ public void onCreateOptionsMenu(Menu menu, MenuInflater inflater) {
MenuItem searchItem = menu.findItem(R.id.menu_search);
SearchManager searchManager = (SearchManager) getActivity().getSystemService(Context.SEARCH_SERVICE);
- final SearchView searchView = (SearchView)MenuItemCompat.getActionView(searchItem);
+ final SearchView searchView = (SearchView) MenuItemCompat.getActionView(searchItem);
searchView.setSearchableInfo(searchManager.getSearchableInfo(getActivity().getComponentName()));
searchView.setOnSuggestionListener(new SearchView.OnSuggestionListener() {
@Override
@@ -244,9 +198,9 @@ public boolean onSuggestionClick(int i) {
int dataIdColumn = cursor.getColumnIndex(SearchManager.SUGGEST_COLUMN_INTENT_DATA);
String itemType = cursor.getString(typeColumn);
int itemId = cursor.getInt(dataIdColumn);
- if(ChannelSearchProvider.INTENT_DATA_CHANNEL.equals(itemType)) {
+ if (ChannelSearchProvider.INTENT_DATA_CHANNEL.equals(itemType)) {
try {
- if(getService().getSessionChannel().getId() != itemId) {
+ if (getService().getSessionChannel().getId() != itemId) {
getService().joinChannel(itemId);
} else {
scrollToChannel(itemId);
@@ -255,7 +209,7 @@ public boolean onSuggestionClick(int i) {
e.printStackTrace();
}
return true;
- } else if(ChannelSearchProvider.INTENT_DATA_USER.equals(itemType)) {
+ } else if (ChannelSearchProvider.INTENT_DATA_USER.equals(itemType)) {
scrollToUser(itemId);
return true;
}
@@ -274,7 +228,7 @@ public boolean onOptionsItemSelected(MenuItem item) {
boolean muted = !self.isSelfMuted();
boolean deafened = self.isSelfDeafened();
- deafened &= muted; // Undeafen if mute is off
+ deafened &= muted;
self.setSelfMuted(muted);
self.setSelfDeafened(deafened);
getService().setSelfMuteDeafState(self.isSelfMuted(), self.isSelfDeafened());
@@ -300,14 +254,6 @@ public boolean onOptionsItemSelected(MenuItem item) {
return true;
case R.id.menu_search:
return false;
- /*case R.id.menu_bluetooth:
- item.setChecked(!item.isChecked());
- try {
- getService().setBluetoothEnabled(item.isChecked());
- } catch (RemoteException e) {
- e.printStackTrace();
- }
- return true;*/
}
return super.onOptionsItemSelected(item);
@@ -319,22 +265,17 @@ private void setupChannelList() throws RemoteException {
mChannelListAdapter.setOnUserClickListener(this);
mChannelView.setAdapter(mChannelListAdapter);
mChannelListAdapter.notifyDataSetChanged();
- }
+ }
- /**
- * Scrolls to the passed channel.
- */
- public void scrollToChannel(int channelId) {
- int channelPosition = mChannelListAdapter.getChannelPosition(channelId);
+ public void scrollToChannel(int channelId) {
+ int channelPosition = mChannelListAdapter.getChannelPosition(channelId);
mChannelView.smoothScrollToPosition(channelPosition);
}
- /**
- * Scrolls to the passed user.
- */
- public void scrollToUser(int userId) {
- int userPosition = mChannelListAdapter.getUserPosition(userId);
- mChannelView.smoothScrollToPosition(userPosition);
- }
+
+ public void scrollToUser(int userId) {
+ int userPosition = mChannelListAdapter.getUserPosition(userId);
+ mChannelView.smoothScrollToPosition(userPosition);
+ }
private boolean isShowingPinnedChannels() {
return getArguments().getBoolean("pinned");
@@ -344,8 +285,6 @@ private boolean isShowingPinnedChannels() {
public void onLocalUserStateUpdated(final User user) {
try {
mChannelListAdapter.notifyDataSetChanged();
-
- // Add or remove registered user from local mute history
final QRPushToTalkDatabase database = mDatabaseProvider.getDatabase();
final Server server = getService().getConnectedServer();
@@ -376,7 +315,6 @@ public void onChannelClick(Channel channel) {
if (mTargetProvider.getChatTarget() != null &&
channel.equals(mTargetProvider.getChatTarget().getChannel()) &&
mActionMode != null) {
- // Dismiss action mode if double pressed. FIXME: use list view selection instead?
mActionMode.finish();
} else {
ActionMode.Callback cb = new ChannelActionModeCallback(getActivity(),
@@ -388,7 +326,7 @@ public void onDestroyActionMode(ActionMode actionMode) {
mActionMode = null;
}
};
- mActionMode = ((ActionBarActivity)getActivity()).startSupportActionMode(cb);
+ mActionMode = ((ActionBarActivity) getActivity()).startSupportActionMode(cb);
}
}
@@ -397,7 +335,6 @@ public void onUserClick(User user) {
if (mTargetProvider.getChatTarget() != null &&
user.equals(mTargetProvider.getChatTarget().getUser()) &&
mActionMode != null) {
- // Dismiss action mode if double pressed. FIXME: use list view selection instead?
mActionMode.finish();
} else {
ActionMode.Callback cb = new UserActionModeCallback(getActivity(), getService(), user, mTargetProvider, getChildFragmentManager(), this) {
@@ -407,7 +344,7 @@ public void onDestroyActionMode(ActionMode actionMode) {
mActionMode = null;
}
};
- mActionMode = ((ActionBarActivity)getActivity()).startSupportActionMode(cb);
+ mActionMode = ((ActionBarActivity) getActivity()).startSupportActionMode(cb);
}
}
}
diff --git a/app/src/main/java/com/terracom/qrpttbeta/channel/ChannelSearchProvider.java b/app/src/main/java/com/terracom/qrpttbeta/channel/ChannelSearchProvider.java
old mode 100644
new mode 100755
index 15bfd80c..ba8bb321
--- a/app/src/main/java/com/terracom/qrpttbeta/channel/ChannelSearchProvider.java
+++ b/app/src/main/java/com/terracom/qrpttbeta/channel/ChannelSearchProvider.java
@@ -1,20 +1,3 @@
-/*
- * Copyright (C) 2014 Andrew Comminos
- *
- * This program 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 .
- */
-
package com.terracom.qrpttbeta.channel;
import android.app.SearchManager;
@@ -42,60 +25,56 @@
import java.util.Locale;
public class ChannelSearchProvider extends ContentProvider {
-
- public static final String INTENT_DATA_CHANNEL = "channel";
- public static final String INTENT_DATA_USER = "user";
+
+ public static final String INTENT_DATA_CHANNEL = "channel";
+ public static final String INTENT_DATA_USER = "user";
private IJumbleService mService;
private final Object mServiceLock = new Object();
- private ServiceConnection mConn = new ServiceConnection() {
- @Override
- public void onServiceConnected(ComponentName name, IBinder service) {
- mService = (IJumbleService) service;
+ private ServiceConnection mConn = new ServiceConnection() {
+ @Override
+ public void onServiceConnected(ComponentName name, IBinder service) {
+ mService = (IJumbleService) service;
synchronized (mServiceLock) {
mServiceLock.notify();
}
- }
-
- @Override
- public void onServiceDisconnected(ComponentName name) {
- mService = null;
- }
- };
-
- @Override
- public int delete(Uri uri, String selection, String[] selectionArgs) {
- // TODO Auto-generated method stub
- return 0;
- }
-
- @Override
- public String getType(Uri uri) {
- // TODO Auto-generated method stub
- return null;
- }
-
- @Override
- public Uri insert(Uri uri, ContentValues values) {
- // TODO Auto-generated method stub
- return null;
- }
-
- @Override
- public boolean onCreate() {
- return true;
- }
-
-
- @Override
- public Cursor query(Uri uri, String[] projection, String selection,
- String[] selectionArgs, String sortOrder) {
-
- // Try to connect to the service. Wait for conn to establish.
- if(mService == null) {
- Intent serviceIntent = new Intent(getContext(), QRPushToTalkService.class);
- getContext().bindService(serviceIntent, mConn, 0);
+ }
+
+ @Override
+ public void onServiceDisconnected(ComponentName name) {
+ mService = null;
+ }
+ };
+
+ @Override
+ public int delete(Uri uri, String selection, String[] selectionArgs) {
+ return 0;
+ }
+
+ @Override
+ public String getType(Uri uri) {
+ return null;
+ }
+
+ @Override
+ public Uri insert(Uri uri, ContentValues values) {
+ return null;
+ }
+
+ @Override
+ public boolean onCreate() {
+ return true;
+ }
+
+
+ @Override
+ public Cursor query(Uri uri, String[] projection, String selection,
+ String[] selectionArgs, String sortOrder) {
+
+ if (mService == null) {
+ Intent serviceIntent = new Intent(getContext(), QRPushToTalkService.class);
+ getContext().bindService(serviceIntent, mConn, 0);
synchronized (mServiceLock) {
try {
@@ -104,23 +83,23 @@ public Cursor query(Uri uri, String[] projection, String selection,
e.printStackTrace();
}
- if(mService == null) {
+ if (mService == null) {
Log.v(Constants.TAG, "Failed to connect to service from search provider!");
return null;
}
}
- }
-
- String query = "";
- for(int x=0;x channels;
List users;
@@ -132,35 +111,25 @@ public Cursor query(Uri uri, String[] projection, String selection,
return cursor;
}
- for(int x=0;x userSearch(Channel root, String str) throws RemoteException {
List list = new LinkedList();
userSearch(root, str, list);
return list;
}
- /**
- * @see #userSearch(Channel,String)
- */
private void userSearch(Channel root, String str, List users) throws RemoteException {
if (root == null) {
return;
@@ -178,22 +147,12 @@ private void userSearch(Channel root, String str, List users) throws Remot
}
}
- /**
- * Recursively searches the channel tree for a channel with a name containing the given string,
- * ignoring case.
- * @param root The channel to recursively search for subchannels within.
- * @param str The string to match against the channel's name. Case insensitive.
- * @return A list of channels whose names contain str.
- */
private List channelSearch(Channel root, String str) throws RemoteException {
List list = new LinkedList();
channelSearch(root, str, list);
return list;
}
- /**
- * @see #channelSearch(Channel,String)
- */
private void channelSearch(Channel root, String str, List channels) throws RemoteException {
if (root == null) {
return;
@@ -209,11 +168,10 @@ private void channelSearch(Channel root, String str, List channels) thr
}
}
- @Override
- public int update(Uri uri, ContentValues values, String selection,
- String[] selectionArgs) {
- // TODO Auto-generated method stub
- return 0;
- }
+ @Override
+ public int update(Uri uri, ContentValues values, String selection,
+ String[] selectionArgs) {
+ return 0;
+ }
}
diff --git a/app/src/main/java/com/terracom/qrpttbeta/channel/ChatTargetProvider.java b/app/src/main/java/com/terracom/qrpttbeta/channel/ChatTargetProvider.java
old mode 100644
new mode 100755
index a7e5892b..d33e35c1
--- a/app/src/main/java/com/terracom/qrpttbeta/channel/ChatTargetProvider.java
+++ b/app/src/main/java/com/terracom/qrpttbeta/channel/ChatTargetProvider.java
@@ -1,20 +1,3 @@
-/*
- * Copyright (C) 2014 Andrew Comminos
- *
- * This program 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 .
- */
-
package com.terracom.qrpttbeta.channel;
import com.terracom.jumble.model.Channel;
@@ -22,9 +5,6 @@
public interface ChatTargetProvider {
- /**
- * Abstraction for user and channel chat targets.
- */
public class ChatTarget {
private Channel mChannel;
private User mUser;
@@ -46,16 +26,15 @@ public User getUser() {
}
}
- /**
- * Interface for classes which wish to receive chat target change calls.
- * Created by andrew on 06/08/13.
- */
public interface OnChatTargetSelectedListener {
public void onChatTargetSelected(ChatTarget target);
}
public ChatTarget getChatTarget();
+
public void setChatTarget(ChatTarget target);
+
public void registerChatTargetListener(OnChatTargetSelectedListener listener);
+
public void unregisterChatTargetListener(OnChatTargetSelectedListener listener);
}
\ No newline at end of file
diff --git a/app/src/main/java/com/terracom/qrpttbeta/channel/OnChannelClickListener.java b/app/src/main/java/com/terracom/qrpttbeta/channel/OnChannelClickListener.java
old mode 100644
new mode 100755
index 9f4eb713..e2d105ae
--- a/app/src/main/java/com/terracom/qrpttbeta/channel/OnChannelClickListener.java
+++ b/app/src/main/java/com/terracom/qrpttbeta/channel/OnChannelClickListener.java
@@ -1,27 +1,7 @@
-/*
- * Copyright (C) 2014 Andrew Comminos
- *
- * This program 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 .
- */
-
package com.terracom.qrpttbeta.channel;
import com.terracom.jumble.model.Channel;
-/**
- * Created by andrew on 20/10/14.
- */
public interface OnChannelClickListener {
public void onChannelClick(Channel channel);
}
diff --git a/app/src/main/java/com/terracom/qrpttbeta/channel/OnUserClickListener.java b/app/src/main/java/com/terracom/qrpttbeta/channel/OnUserClickListener.java
old mode 100644
new mode 100755
index b1682049..b822da2b
--- a/app/src/main/java/com/terracom/qrpttbeta/channel/OnUserClickListener.java
+++ b/app/src/main/java/com/terracom/qrpttbeta/channel/OnUserClickListener.java
@@ -1,27 +1,7 @@
-/*
- * Copyright (C) 2014 Andrew Comminos
- *
- * This program 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 .
- */
-
package com.terracom.qrpttbeta.channel;
import com.terracom.jumble.model.User;
-/**
- * Created by andrew on 20/10/14.
- */
public interface OnUserClickListener {
public void onUserClick(User user);
}
diff --git a/app/src/main/java/com/terracom/qrpttbeta/channel/ServerInfoFragment.java b/app/src/main/java/com/terracom/qrpttbeta/channel/ServerInfoFragment.java
old mode 100644
new mode 100755
index 157af8cb..1e1c165c
--- a/app/src/main/java/com/terracom/qrpttbeta/channel/ServerInfoFragment.java
+++ b/app/src/main/java/com/terracom/qrpttbeta/channel/ServerInfoFragment.java
@@ -1,20 +1,3 @@
-/*
- * Copyright (C) 2014 Andrew Comminos
- *
- * This program 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 .
- */
-
package com.terracom.qrpttbeta.channel;
import android.os.Bundle;
@@ -28,7 +11,6 @@
import com.terracom.jumble.IJumbleService;
import com.terracom.jumble.JumbleService;
-import com.terracom.jumble.net.JumbleConnection;
import com.terracom.jumble.net.JumbleUDPMessageType;
import com.terracom.qrpttbeta.R;
import com.terracom.qrpttbeta.util.JumbleServiceFragment;
@@ -37,10 +19,6 @@
import java.util.concurrent.ScheduledExecutorService;
import java.util.concurrent.TimeUnit;
-/**
- * A fragment that displays known information from the remote server.
- * Created by andrew on 28/08/13.
- */
public class ServerInfoFragment extends JumbleServiceFragment {
private static final int POLL_RATE = 1000;
@@ -71,17 +49,14 @@ public View onCreateView(LayoutInflater inflater, ViewGroup container, Bundle sa
return view;
}
- /**
- * Updates the info from the service.
- */
public void updateData() throws RemoteException {
- if(getService() == null || getService().getConnectionState() != JumbleService.STATE_CONNECTED)
+ if (getService() == null || getService().getConnectionState() != JumbleService.STATE_CONNECTED)
return;
mProtocolView.setText(getString(R.string.server_info_protocol, getService().getServerRelease()));
mOSVersionView.setText(getString(R.string.server_info_version, getService().getServerOSName(), getService().getServerOSVersion()));
- mTCPLatencyView.setText(getString(R.string.server_info_latency, (float)getService().getTCPLatency()*Math.pow(10, -3)));
- mUDPLatencyView.setText(getString(R.string.server_info_latency, (float)getService().getUDPLatency()*Math.pow(10, -3)));
+ mTCPLatencyView.setText(getString(R.string.server_info_latency, (float) getService().getTCPLatency() * Math.pow(10, -3)));
+ mUDPLatencyView.setText(getString(R.string.server_info_latency, (float) getService().getUDPLatency() * Math.pow(10, -3)));
mHostView.setText(getString(R.string.server_info_host, getService().getConnectedServer().getHost(), getService().getConnectedServer().getPort()));
String codecName;
@@ -103,14 +78,13 @@ public void updateData() throws RemoteException {
codecName = "???";
}
- mMaxBandwidthView.setText(getString(R.string.server_info_max_bandwidth, (float)getService().getMaxBandwidth()/1000f));
- mCurrentBandwidthView.setText(getString(R.string.server_info_current_bandwidth, (float)getService().getCurrentBandwidth()/1000f));
+ mMaxBandwidthView.setText(getString(R.string.server_info_max_bandwidth, (float) getService().getMaxBandwidth() / 1000f));
+ mCurrentBandwidthView.setText(getString(R.string.server_info_current_bandwidth, (float) getService().getCurrentBandwidth() / 1000f));
mCodecView.setText(getString(R.string.server_info_codec, codecName));
}
@Override
public void onServiceBound(IJumbleService service) {
- // wow this is ugly
mExecutorService.scheduleAtFixedRate(new Runnable() {
@Override
public void run() {
@@ -118,7 +92,7 @@ public void run() {
@Override
public void run() {
try {
- if(!isDetached()) updateData();
+ if (!isDetached()) updateData();
} catch (RemoteException e) {
e.printStackTrace();
}
diff --git a/app/src/main/java/com/terracom/qrpttbeta/channel/actionmode/ChannelActionModeCallback.java b/app/src/main/java/com/terracom/qrpttbeta/channel/actionmode/ChannelActionModeCallback.java
old mode 100644
new mode 100755
index f7ab2c6c..902563a1
--- a/app/src/main/java/com/terracom/qrpttbeta/channel/actionmode/ChannelActionModeCallback.java
+++ b/app/src/main/java/com/terracom/qrpttbeta/channel/actionmode/ChannelActionModeCallback.java
@@ -1,20 +1,3 @@
-/*
- * Copyright (C) 2014 Andrew Comminos
- *
- * This program 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 .
- */
-
package com.terracom.qrpttbeta.channel.actionmode;
import android.app.AlertDialog;
@@ -40,12 +23,6 @@
import com.terracom.qrpttbeta.db.QRPushToTalkDatabase;
import com.terracom.qrpttbeta.util.TintedMenuInflater;
-/**
- * Contextual action mode for channels.
- * When the action mode is activated, the user is set to the current chat target.
- * Upon dismissal, the chat target is reset (usually to the current channel).
- * Created by andrew on 24/06/14.
- */
public class ChannelActionModeCallback extends ChatTargetActionModeCallback {
private Context mContext;
private IJumbleService mService;
@@ -77,8 +54,7 @@ public boolean onCreateActionMode(ActionMode actionMode, Menu menu) {
actionMode.setSubtitle(R.string.current_chat_target);
try {
- // Request permissions update from server, if we don't have channel permissions
- if(mChannel.getPermissions() == 0)
+ if (mChannel.getPermissions() == 0)
mService.requestPermissions(mChannel.getId());
} catch (RemoteException e) {
e.printStackTrace();
@@ -89,10 +65,6 @@ public boolean onCreateActionMode(ActionMode actionMode, Menu menu) {
@Override
public boolean onPrepareActionMode(ActionMode actionMode, Menu menu) {
int perms = mChannel.getPermissions();
-
- // This breaks uMurmur ACL. Put in a fix based on server version perhaps?
- //menu.getMenu().findItem(R.id.menu_channel_add)
- // .setVisible((permissions & (Permissions.MakeChannel | Permissions.MakeTempChannel)) > 0);
menu.findItem(R.id.context_channel_edit).setVisible((perms & Permissions.Write) > 0);
menu.findItem(R.id.context_channel_remove).setVisible((perms & Permissions.Write) > 0);
menu.findItem(R.id.context_channel_view_description)
@@ -101,9 +73,7 @@ public boolean onPrepareActionMode(ActionMode actionMode, Menu menu) {
try {
Server server = mService.getConnectedServer();
- if(server != null) {
-// menu.findItem(R.id.context_channel_pin)
-// .setChecked(mDatabase.isChannelPinned(server.getId(), mChannel.getId()));
+ if (server != null) {
}
} catch (RemoteException e) {
e.printStackTrace();
@@ -115,7 +85,7 @@ public boolean onPrepareActionMode(ActionMode actionMode, Menu menu) {
@Override
public boolean onActionItemClicked(ActionMode actionMode, MenuItem menuItem) {
boolean adding = false;
- switch(menuItem.getItemId()) {
+ switch (menuItem.getItemId()) {
case R.id.context_channel_join:
try {
mService.joinChannel(mChannel.getId());
@@ -128,7 +98,7 @@ public boolean onActionItemClicked(ActionMode actionMode, MenuItem menuItem) {
case R.id.context_channel_edit:
ChannelEditFragment addFragment = new ChannelEditFragment();
Bundle args = new Bundle();
- if(adding) args.putInt("parent", mChannel.getId());
+ if (adding) args.putInt("parent", mChannel.getId());
else args.putInt("channel", mChannel.getId());
args.putBoolean("adding", adding);
addFragment.setArguments(args);
@@ -160,16 +130,6 @@ public void onClick(DialogInterface dialog, int which) {
ChannelDescriptionFragment.class.getName(), commentArgs);
commentFragment.show(mFragmentManager, ChannelDescriptionFragment.class.getName());
break;
-/* case R.id.context_channel_pin:
- try {
- long serverId = mService.getConnectedServer().getId();
- boolean pinned = mDatabase.isChannelPinned(serverId, mChannel.getId());
- if(!pinned) mDatabase.addPinnedChannel(serverId, mChannel.getId());
- else mDatabase.removePinnedChannel(serverId, mChannel.getId());
- } catch (RemoteException e) {
- e.printStackTrace();
- }
- break;*/
}
actionMode.finish();
return true;
diff --git a/app/src/main/java/com/terracom/qrpttbeta/channel/actionmode/ChatTargetActionModeCallback.java b/app/src/main/java/com/terracom/qrpttbeta/channel/actionmode/ChatTargetActionModeCallback.java
old mode 100644
new mode 100755
index e6ac339d..3fd58291
--- a/app/src/main/java/com/terracom/qrpttbeta/channel/actionmode/ChatTargetActionModeCallback.java
+++ b/app/src/main/java/com/terracom/qrpttbeta/channel/actionmode/ChatTargetActionModeCallback.java
@@ -1,20 +1,3 @@
-/*
- * Copyright (C) 2014 Andrew Comminos
- *
- * This program 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 .
- */
-
package com.terracom.qrpttbeta.channel.actionmode;
import android.support.v7.view.ActionMode;
@@ -22,11 +5,6 @@
import com.terracom.qrpttbeta.channel.ChatTargetProvider;
-/**
- * A callback that sets the active chat target when activated, and resets when destroyed (usually
- * to the user's current channel).
- * Created by andrew on 26/06/14.
- */
public abstract class ChatTargetActionModeCallback implements ActionMode.Callback {
private ChatTargetProvider mProvider;
diff --git a/app/src/main/java/com/terracom/qrpttbeta/channel/actionmode/UserActionModeCallback.java b/app/src/main/java/com/terracom/qrpttbeta/channel/actionmode/UserActionModeCallback.java
old mode 100644
new mode 100755
index db6d8dcb..f6e1b46b
--- a/app/src/main/java/com/terracom/qrpttbeta/channel/actionmode/UserActionModeCallback.java
+++ b/app/src/main/java/com/terracom/qrpttbeta/channel/actionmode/UserActionModeCallback.java
@@ -1,20 +1,3 @@
-/*
- * Copyright (C) 2014 Andrew Comminos
- *
- * This program 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 .
- */
-
package com.terracom.qrpttbeta.channel.actionmode;
import android.app.AlertDialog;
@@ -41,12 +24,6 @@
import java.util.List;
-/**
- * Contextual action mode for users.
- * When the action mode is activated, the user is set to the current chat target.
- * Upon dismissal, the chat target is reset (usually to the channel).
- * Created by andrew on 24/06/14.
- */
public class UserActionModeCallback extends ChatTargetActionModeCallback {
private Context mContext;
private IJumbleService mService;
@@ -78,9 +55,8 @@ public boolean onCreateActionMode(ActionMode actionMode, Menu menu) {
actionMode.setSubtitle(R.string.current_chat_target);
try {
- // Request permissions update from server, if we don't have channel permissions
Channel channel = mService.getChannel(mUser.getChannelId());
- if(channel != null && channel.getPermissions() == 0)
+ if (channel != null && channel.getPermissions() == 0)
mService.requestPermissions(mUser.getChannelId());
} catch (RemoteException e) {
e.printStackTrace();
@@ -92,7 +68,6 @@ public boolean onCreateActionMode(ActionMode actionMode, Menu menu) {
@Override
public boolean onPrepareActionMode(ActionMode actionMode, Menu menu) {
try {
- // Use permission data to determine the actions available.
boolean self = mUser.getSession() == mService.getSession();
int perms = mService.getPermissions();
Channel channel = mService.getChannel(mUser.getChannelId());
@@ -126,10 +101,6 @@ public boolean onPrepareActionMode(ActionMode actionMode, Menu menu) {
menu.findItem(R.id.context_local_mute).setVisible(!self);
menu.findItem(R.id.context_ignore_messages).setVisible(!self);
- // TODO info
-// informationItem.enabled = (((perms & (Permissions.Write | Permissions.Register))) > 0 || (channelPermissions & (Permissions.Write | Permissions.Enter)) > 0 || (mUser.getSession() == mService.getSession()));
-
- // Highlight toggles
menu.findItem(R.id.context_mute).setChecked(mUser.isMuted() || mUser.isSuppressed());
menu.findItem(R.id.context_deafen).setChecked(mUser.isDeafened());
menu.findItem(R.id.context_priority).setChecked(mUser.isPrioritySpeaker());
@@ -147,15 +118,6 @@ public boolean onActionItemClicked(ActionMode actionMode, MenuItem menuItem) {
try {
boolean ban = false;
switch (menuItem.getItemId()) {
-// case R.id.context_send_message:
-// if(mChatTargetProvider.getChatTarget() != null &&
-// mChatTargetProvider.getChatTarget().getUser() != null &&
-// mChatTargetProvider.getChatTarget().getUser().equals(mUser)) {
-// mChatTargetProvider.setChatTarget(null);
-// } else {
-// mChatTargetProvider.setChatTarget(new ChatTargetProvider.ChatTarget(mUser));
-// }
-// break;
case R.id.context_ban:
ban = true;
case R.id.context_kick:
@@ -220,8 +182,6 @@ public void onClick(DialogInterface dialog, int which) {
.setNegativeButton(android.R.string.cancel, null)
.show();
break;
-// case R.id.context_info:
-// break;
case R.id.context_register:
mService.registerUser(mUser.getSession());
break;
@@ -230,7 +190,7 @@ public void onClick(DialogInterface dialog, int which) {
e.printStackTrace();
return false;
}
- actionMode.finish(); // FIXME?
+ actionMode.finish();
return true;
}
@@ -275,12 +235,6 @@ public void onClick(DialogInterface dialog, int which) {
adb.show();
}
- /**
- * Interface for observers that wish to be notified when the user state needs to be redrawn.
- * Note that this is only for local changes- server-side state changes will be propagated to
- * the respective Jumble callbacks.
- * i.e. if the user becomes local muted.
- */
public interface LocalUserUpdateListener {
public void onLocalUserStateUpdated(User user);
}
diff --git a/app/src/main/java/com/terracom/qrpttbeta/channel/comment/AbstractCommentFragment.java b/app/src/main/java/com/terracom/qrpttbeta/channel/comment/AbstractCommentFragment.java
old mode 100644
new mode 100755
index 8c0af9bd..db6e9cc1
--- a/app/src/main/java/com/terracom/qrpttbeta/channel/comment/AbstractCommentFragment.java
+++ b/app/src/main/java/com/terracom/qrpttbeta/channel/comment/AbstractCommentFragment.java
@@ -1,20 +1,3 @@
-/*
- * Copyright (C) 2014 Andrew Comminos
- *
- * This program 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 .
- */
-
package com.terracom.qrpttbeta.channel.comment;
import android.app.Activity;
@@ -34,10 +17,6 @@
import com.terracom.qrpttbeta.R;
import com.terracom.qrpttbeta.util.JumbleServiceProvider;
-/**
- * Fragment to change your comment using basic WYSIWYG tools.
- * Created by andrew on 10/08/13.
- */
public abstract class AbstractCommentFragment extends DialogFragment {
private TabHost mTabHost;
@@ -74,7 +53,7 @@ public Dialog onCreateDialog(Bundle savedInstanceState) {
mTabHost = (TabHost) view.findViewById(R.id.comment_tabhost);
mTabHost.setup();
- if(mComment == null) {
+ if (mComment == null) {
mCommentView.loadData("Loading...", null, null);
try {
requestComment(mProvider.getService());
@@ -99,11 +78,9 @@ public Dialog onCreateDialog(Bundle savedInstanceState) {
mTabHost.setOnTabChangedListener(new TabHost.OnTabChangeListener() {
@Override
public void onTabChanged(String tabId) {
- if("View".equals(tabId)) {
- // When switching back to view tab, update with user's HTML changes.
+ if ("View".equals(tabId)) {
mCommentView.loadData(mCommentEdit.getText().toString(), "text/html", "UTF-8");
- } else if("Edit".equals(tabId) && "".equals(mCommentEdit.getText().toString())) {
- // Load edittext content for the first time when the tab is selected, to improve performance with long messages.
+ } else if ("Edit".equals(tabId) && "".equals(mCommentEdit.getText().toString())) {
mCommentEdit.setText(mComment);
}
}
@@ -130,7 +107,7 @@ public void onClick(DialogInterface dialog, int which) {
}
protected void loadComment(String comment) {
- if(mCommentView == null) return;
+ if (mCommentView == null) return;
mCommentView.loadData(comment, "text/html", "UTF-8");
mComment = comment;
}
@@ -139,17 +116,7 @@ public boolean isEditing() {
return getArguments().getBoolean("editing");
}
- /**
- * Requests a comment from the service. Will not be called if we already have a comment provided.
- * This method is expected to set a callback that will call {@link com.terracom.qrpttbeta.channel.comment.AbstractCommentFragment#loadComment(String comment)}.
- * @param service The bound Jumble service to use for remote calls.
- */
public abstract void requestComment(IJumbleService service) throws RemoteException;
- /**
- * Asks the service to replace the comment.
- * @param service The bound Jumble service to use for remote calls.
- * @param comment The comment the user has defined.
- */
public abstract void editComment(IJumbleService service, String comment) throws RemoteException;
}
diff --git a/app/src/main/java/com/terracom/qrpttbeta/channel/comment/ChannelDescriptionFragment.java b/app/src/main/java/com/terracom/qrpttbeta/channel/comment/ChannelDescriptionFragment.java
old mode 100644
new mode 100755
index 344aca42..94baa6ed
--- a/app/src/main/java/com/terracom/qrpttbeta/channel/comment/ChannelDescriptionFragment.java
+++ b/app/src/main/java/com/terracom/qrpttbeta/channel/comment/ChannelDescriptionFragment.java
@@ -1,20 +1,3 @@
-/*
- * Copyright (C) 2014 Andrew Comminos
- *
- * This program 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 .
- */
-
package com.terracom.qrpttbeta.channel.comment;
import android.os.RemoteException;
@@ -23,9 +6,6 @@
import com.terracom.jumble.model.Channel;
import com.terracom.jumble.util.JumbleObserver;
-/**
- * Created by andrew on 03/03/14.
- */
public class ChannelDescriptionFragment extends AbstractCommentFragment {
@Override
@@ -33,7 +13,7 @@ public void requestComment(final IJumbleService service) throws RemoteException
service.registerObserver(new JumbleObserver() {
@Override
public void onChannelStateUpdated(Channel channel) throws RemoteException {
- if(channel.getId() == getChannelId() &&
+ if (channel.getId() == getChannelId() &&
channel.getDescription() != null) {
loadComment(channel.getDescription());
service.unregisterObserver(this);
@@ -45,7 +25,6 @@ public void onChannelStateUpdated(Channel channel) throws RemoteException {
@Override
public void editComment(IJumbleService service, String comment) throws RemoteException {
- // TODO
}
private int getChannelId() {
diff --git a/app/src/main/java/com/terracom/qrpttbeta/channel/comment/UserCommentFragment.java b/app/src/main/java/com/terracom/qrpttbeta/channel/comment/UserCommentFragment.java
old mode 100644
new mode 100755
index 61e16db8..2629114b
--- a/app/src/main/java/com/terracom/qrpttbeta/channel/comment/UserCommentFragment.java
+++ b/app/src/main/java/com/terracom/qrpttbeta/channel/comment/UserCommentFragment.java
@@ -1,20 +1,3 @@
-/*
- * Copyright (C) 2014 Andrew Comminos
- *
- * This program 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 .
- */
-
package com.terracom.qrpttbeta.channel.comment;
import android.os.RemoteException;
@@ -23,9 +6,6 @@
import com.terracom.jumble.model.User;
import com.terracom.jumble.util.JumbleObserver;
-/**
- * Created by andrew on 03/03/14.
- */
public class UserCommentFragment extends AbstractCommentFragment {
@Override
@@ -33,7 +13,7 @@ public void requestComment(final IJumbleService service) throws RemoteException
service.registerObserver(new JumbleObserver() {
@Override
public void onUserStateUpdated(User user) throws RemoteException {
- if(user.getSession() == getSession() &&
+ if (user.getSession() == getSession() &&
user.getComment() != null) {
loadComment(user.getComment());
service.unregisterObserver(this);
diff --git a/app/src/main/java/com/terracom/qrpttbeta/db/DatabaseProvider.java b/app/src/main/java/com/terracom/qrpttbeta/db/DatabaseProvider.java
old mode 100644
new mode 100755
index 102c50c4..f15ad310
--- a/app/src/main/java/com/terracom/qrpttbeta/db/DatabaseProvider.java
+++ b/app/src/main/java/com/terracom/qrpttbeta/db/DatabaseProvider.java
@@ -1,25 +1,5 @@
-/*
- * Copyright (C) 2014 Andrew Comminos
- *
- * This program 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 .
- */
-
package com.terracom.qrpttbeta.db;
-/**
- * Created by andrew on 15/08/13.
- */
public interface DatabaseProvider {
public QRPushToTalkDatabase getDatabase();
}
diff --git a/app/src/main/java/com/terracom/qrpttbeta/db/PublicServer.java b/app/src/main/java/com/terracom/qrpttbeta/db/PublicServer.java
old mode 100644
new mode 100755
index fde7bc32..963b4a35
--- a/app/src/main/java/com/terracom/qrpttbeta/db/PublicServer.java
+++ b/app/src/main/java/com/terracom/qrpttbeta/db/PublicServer.java
@@ -1,20 +1,3 @@
-/*
- * Copyright (C) 2014 Andrew Comminos
- *
- * This program 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 .
- */
-
package com.terracom.qrpttbeta.db;
@@ -22,44 +5,32 @@
public class PublicServer extends Server {
- private String mCA;
- private String mContinentCode;
- private String mCountry;
- private String mCountryCode;
- private String mRegion;
- private String mUrl;
-
- public PublicServer(String name, String ca, String continentCode, String country, String countryCode, String ip, Integer port, String region, String url) {
- super(-1, name, ip, port, "", "");
- mCA = ca;
- mContinentCode = continentCode;
- mCountry = country;
- mCountryCode = countryCode;
- mRegion = region;
- mUrl = url;
- }
-
- public String getCA() {
- return mCA;
- }
-
- public String getContinentCode() {
- return mContinentCode;
- }
-
- public String getCountry() {
- return mCountry;
- }
+ private String mCA;
+ private String mContinentCode;
+ private String mCountry;
+ private String mCountryCode;
+ private String mRegion;
+ private String mUrl;
- public String getCountryCode() {
- return mCountryCode;
- }
-
- public String getRegion() {
- return mRegion;
- }
-
- public String getUrl() {
- return mUrl;
- }
+ public PublicServer(String name, String ca, String continentCode, String country, String countryCode, String ip, Integer port, String region, String url) {
+ super(-1, name, ip, port, "", "");
+ mCA = ca;
+ mContinentCode = continentCode;
+ mCountry = country;
+ mCountryCode = countryCode;
+ mRegion = region;
+ mUrl = url;
+ }
+
+ public String getCountry() {
+ return mCountry;
+ }
+
+ public String getCountryCode() {
+ return mCountryCode;
+ }
+
+ public String getUrl() {
+ return mUrl;
+ }
}
diff --git a/app/src/main/java/com/terracom/qrpttbeta/db/QRPushToTalkDatabase.java b/app/src/main/java/com/terracom/qrpttbeta/db/QRPushToTalkDatabase.java
old mode 100644
new mode 100755
index be49365d..2d33141c
--- a/app/src/main/java/com/terracom/qrpttbeta/db/QRPushToTalkDatabase.java
+++ b/app/src/main/java/com/terracom/qrpttbeta/db/QRPushToTalkDatabase.java
@@ -1,56 +1,35 @@
-/*
- * Copyright (C) 2014 Andrew Comminos
- *
- * This program 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 .
- */
-
package com.terracom.qrpttbeta.db;
import com.terracom.jumble.model.Server;
import java.util.List;
-/**
- * An interface for persistent storage services (i.e. databases, cloud) to implement.
- * Created by andrew on 13/08/13.
- */
public interface QRPushToTalkDatabase {
public void open();
+
public void close();
public List getServers();
+
public void addServer(Server server);
+
public void updateServer(Server server);
- public void removeServer(Server server);
- public boolean isCommentSeen(String hash, byte[] commentHash);
- public void markCommentSeen(String hash, byte[] commentHash);
+ public void removeServer(Server server);
public List getPinnedChannels(long serverId);
- public void addPinnedChannel(long serverId, int channelId);
- public void removePinnedChannel(long serverId, int channelId);
- public boolean isChannelPinned(long serverId, int channelId);
public List getAccessTokens(long serverId);
- public void addAccessToken(long serverId, String token);
- public void removeAccessToken(long serverId, String token);
public List getLocalMutedUsers(long serverId);
+
public void addLocalMutedUser(long serverId, int userId);
+
public void removeLocalMutedUser(long serverId, int userId);
public List getLocalIgnoredUsers(long serverId);
+
public void addLocalIgnoredUser(long serverId, int userId);
+
public void removeLocalIgnoredUser(long serverId, int userId);
}
diff --git a/app/src/main/java/com/terracom/qrpttbeta/db/QRPushToTalkSQLiteDatabase.java b/app/src/main/java/com/terracom/qrpttbeta/db/QRPushToTalkSQLiteDatabase.java
old mode 100644
new mode 100755
index 4318fd2f..d5a6cbf6
--- a/app/src/main/java/com/terracom/qrpttbeta/db/QRPushToTalkSQLiteDatabase.java
+++ b/app/src/main/java/com/terracom/qrpttbeta/db/QRPushToTalkSQLiteDatabase.java
@@ -1,20 +1,3 @@
-/*
- * Copyright (C) 2014 Andrew Comminos
- *
- * This program 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 .
- */
-
package com.terracom.qrpttbeta.db;
import android.content.ContentValues;
@@ -83,7 +66,7 @@ public class QRPushToTalkSQLiteDatabase extends SQLiteOpenHelper implements QRPu
public static final String LOCAL_MUTE_SERVER = "server";
public static final String LOCAL_MUTE_USER = "user";
public static final String TABLE_LOCAL_MUTE_CREATE_SQL = "CREATE TABLE IF NOT EXISTS " + TABLE_LOCAL_MUTE + " ("
- + "`" + LOCAL_MUTE_SERVER +"` INTEGER NOT NULL,"
+ + "`" + LOCAL_MUTE_SERVER + "` INTEGER NOT NULL,"
+ "`" + LOCAL_MUTE_USER + "` INTEGER NOT NULL,"
+ "CONSTRAINT server_user UNIQUE(" + LOCAL_MUTE_SERVER + "," + LOCAL_MUTE_USER + ")"
+ ");";
@@ -92,7 +75,7 @@ public class QRPushToTalkSQLiteDatabase extends SQLiteOpenHelper implements QRPu
public static final String LOCAL_IGNORE_SERVER = "server";
public static final String LOCAL_IGNORE_USER = "user";
public static final String TABLE_LOCAL_IGNORE_CREATE_SQL = "CREATE TABLE IF NOT EXISTS " + TABLE_LOCAL_IGNORE + " ("
- + "`" + LOCAL_IGNORE_SERVER +"` INTEGER NOT NULL,"
+ + "`" + LOCAL_IGNORE_SERVER + "` INTEGER NOT NULL,"
+ "`" + LOCAL_IGNORE_USER + "` INTEGER NOT NULL,"
+ "CONSTRAINT server_user UNIQUE(" + LOCAL_IGNORE_SERVER + "," + LOCAL_IGNORE_USER + ")"
+ ");";
@@ -151,7 +134,6 @@ public void onUpgrade(
@Override
public void open() {
- // Do nothing. Database will be opened automatically when accessing it.
}
@Override
@@ -215,16 +197,15 @@ public void updateServer(Server server) {
@Override
public void removeServer(Server server) {
getWritableDatabase().delete(TABLE_SERVER, SERVER_ID + "=?",
- new String[] { String.valueOf(server.getId()) });
- // Clean up server-specific entries
+ new String[]{String.valueOf(server.getId())});
getWritableDatabase().delete(TABLE_FAVOURITES, FAVOURITES_SERVER + "=?",
- new String[] { String.valueOf(server.getId()) });
+ new String[]{String.valueOf(server.getId())});
getWritableDatabase().delete(TABLE_TOKENS, TOKENS_SERVER + "=?",
- new String[] { String.valueOf(server.getId()) });
+ new String[]{String.valueOf(server.getId())});
getWritableDatabase().delete(TABLE_LOCAL_MUTE, LOCAL_MUTE_SERVER + "=?",
- new String[] { String.valueOf(server.getId()) });
+ new String[]{String.valueOf(server.getId())});
getWritableDatabase().delete(TABLE_LOCAL_IGNORE, LOCAL_IGNORE_SERVER + "=?",
- new String[] { String.valueOf(server.getId()) });
+ new String[]{String.valueOf(server.getId())});
}
public List getPinnedChannels(long serverId) {
@@ -250,39 +231,12 @@ public List getPinnedChannels(long serverId) {
return favourites;
}
- @Override
- public void addPinnedChannel(long serverId, int channelId) {
- ContentValues contentValues = new ContentValues();
- contentValues.put(FAVOURITES_CHANNEL, channelId);
- contentValues.put(FAVOURITES_SERVER, serverId);
- getWritableDatabase().insert(TABLE_FAVOURITES, null, contentValues);
- }
-
- @Override
- public boolean isChannelPinned(long serverId, int channelId) {
- Cursor c = getReadableDatabase().query(
- TABLE_FAVOURITES,
- new String[]{FAVOURITES_CHANNEL},
- FAVOURITES_SERVER + "=? AND " +
- FAVOURITES_CHANNEL + "=?",
- new String[]{String.valueOf(serverId), String.valueOf(channelId)},
- null,
- null,
- null);
- c.moveToFirst();
- return !c.isAfterLast();
- }
-
- public void removePinnedChannel(long serverId, int channelId) {
- getWritableDatabase().delete(TABLE_FAVOURITES, "server = ? AND channel = ?", new String[] { Long.toString(serverId), Integer.toString(channelId)});
- }
-
@Override
public List getAccessTokens(long serverId) {
- Cursor cursor = getReadableDatabase().query(TABLE_TOKENS, new String[] { TOKENS_VALUE }, TOKENS_SERVER+"=?", new String[] { String.valueOf(serverId) }, null, null, null);
+ Cursor cursor = getReadableDatabase().query(TABLE_TOKENS, new String[]{TOKENS_VALUE}, TOKENS_SERVER + "=?", new String[]{String.valueOf(serverId)}, null, null, null);
cursor.moveToFirst();
List tokens = new ArrayList();
- while(!cursor.isAfterLast()) {
+ while (!cursor.isAfterLast()) {
tokens.add(cursor.getString(0));
cursor.moveToNext();
}
@@ -290,25 +244,12 @@ public List getAccessTokens(long serverId) {
return tokens;
}
- @Override
- public void addAccessToken(long serverId, String token) {
- ContentValues contentValues = new ContentValues();
- contentValues.put(TOKENS_SERVER, serverId);
- contentValues.put(TOKENS_VALUE, token);
- getWritableDatabase().insert(TABLE_TOKENS, null, contentValues);
- }
-
- @Override
- public void removeAccessToken(long serverId, String token) {
- getWritableDatabase().delete(TABLE_TOKENS, TOKENS_SERVER+"=? AND "+TOKENS_VALUE+"=?", new String[] {String.valueOf(serverId), token });
- }
-
@Override
public List getLocalMutedUsers(long serverId) {
Cursor cursor = getReadableDatabase().query(TABLE_LOCAL_MUTE,
- new String[] { LOCAL_MUTE_USER },
+ new String[]{LOCAL_MUTE_USER},
LOCAL_MUTE_SERVER + "=?",
- new String[] { String.valueOf(serverId) },
+ new String[]{String.valueOf(serverId)},
null, null, null);
cursor.moveToNext();
List users = new ArrayList();
@@ -331,15 +272,15 @@ public void addLocalMutedUser(long serverId, int userId) {
public void removeLocalMutedUser(long serverId, int userId) {
getWritableDatabase().delete(TABLE_LOCAL_MUTE,
LOCAL_MUTE_SERVER + "=? AND " + LOCAL_MUTE_USER + "=?",
- new String[] { String.valueOf(serverId), String.valueOf(userId) });
+ new String[]{String.valueOf(serverId), String.valueOf(userId)});
}
@Override
public List getLocalIgnoredUsers(long serverId) {
Cursor cursor = getReadableDatabase().query(TABLE_LOCAL_IGNORE,
- new String[] { LOCAL_IGNORE_USER },
+ new String[]{LOCAL_IGNORE_USER},
LOCAL_IGNORE_SERVER + "=?",
- new String[] { String.valueOf(serverId) },
+ new String[]{String.valueOf(serverId)},
null, null, null);
cursor.moveToFirst();
List users = new ArrayList();
@@ -362,26 +303,6 @@ public void addLocalIgnoredUser(long serverId, int userId) {
public void removeLocalIgnoredUser(long serverId, int userId) {
getWritableDatabase().delete(TABLE_LOCAL_IGNORE,
LOCAL_IGNORE_SERVER + "=? AND " + LOCAL_IGNORE_USER + "=?",
- new String[] { String.valueOf(serverId), String.valueOf(userId) });
- }
-
- @Override
- public boolean isCommentSeen(String hash, byte[] commentHash) {
- Cursor cursor = getReadableDatabase().query(TABLE_COMMENTS,
- new String[]{COMMENTS_WHO, COMMENTS_COMMENT, COMMENTS_SEEN}, COMMENTS_WHO + "=? AND " + COMMENTS_COMMENT + "=?",
- new String[]{hash, new String(commentHash)},
- null, null, null);
- boolean hasNext = cursor.moveToNext();
- cursor.close();
- return hasNext;
- }
-
- @Override
- public void markCommentSeen(String hash, byte[] commentHash) {
- ContentValues values = new ContentValues();
- values.put(COMMENTS_WHO, hash);
- values.put(COMMENTS_COMMENT, commentHash);
- values.put(COMMENTS_SEEN, "datetime('now')");
- getWritableDatabase().replace(TABLE_COMMENTS, null, values);
+ new String[]{String.valueOf(serverId), String.valueOf(userId)});
}
}
diff --git a/app/src/main/java/com/terracom/qrpttbeta/drawable/CircleDrawable.java b/app/src/main/java/com/terracom/qrpttbeta/drawable/CircleDrawable.java
old mode 100644
new mode 100755
index e64231ff..8a5a91a4
--- a/app/src/main/java/com/terracom/qrpttbeta/drawable/CircleDrawable.java
+++ b/app/src/main/java/com/terracom/qrpttbeta/drawable/CircleDrawable.java
@@ -1,20 +1,3 @@
-/*
- * Copyright (C) 2014 Andrew Comminos
- *
- * This program 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 .
- */
-
package com.terracom.qrpttbeta.drawable;
import android.content.res.Resources;
@@ -32,10 +15,6 @@
import com.terracom.qrpttbeta.R;
-/**
- * A drawable containing a circular bitmap in the style of @drawable/outline_circle_talking_off.
- * Created by andrew on 19/10/14.
- */
public class CircleDrawable extends Drawable {
public static final int STROKE_WIDTH_DP = 1;
private Resources mResources;
@@ -89,9 +68,8 @@ protected void onBoundsChange(Rect bounds) {
public void draw(Canvas canvas) {
RectF imageRect = new RectF(getBounds());
RectF strokeRect = new RectF(getBounds());
- // Default stroke drawing is both inset and outset.
- strokeRect.inset(mStrokePaint.getStrokeWidth()/2,
- mStrokePaint.getStrokeWidth()/2);
+ strokeRect.inset(mStrokePaint.getStrokeWidth() / 2,
+ mStrokePaint.getStrokeWidth() / 2);
canvas.drawOval(imageRect, mPaint);
canvas.drawOval(strokeRect, mStrokePaint);
diff --git a/app/src/main/java/com/terracom/qrpttbeta/drawable/FlipDrawable.java b/app/src/main/java/com/terracom/qrpttbeta/drawable/FlipDrawable.java
old mode 100644
new mode 100755
index 00d2c361..a70d9e6d
--- a/app/src/main/java/com/terracom/qrpttbeta/drawable/FlipDrawable.java
+++ b/app/src/main/java/com/terracom/qrpttbeta/drawable/FlipDrawable.java
@@ -1,20 +1,3 @@
-/*
- * Copyright (C) 2014 Andrew Comminos
- *
- * This program 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 .
- */
-
package com.terracom.qrpttbeta.drawable;
import android.animation.ValueAnimator;
@@ -24,10 +7,6 @@
import android.graphics.drawable.Drawable;
import android.graphics.drawable.LayerDrawable;
-/**
- * A transition drawable that shows a "flip" between two different images.
- * Created by andrew on 19/10/14.
- */
@TargetApi(11)
public class FlipDrawable extends LayerDrawable implements ValueAnimator.AnimatorUpdateListener {
private Drawable mFrom;
@@ -36,7 +15,7 @@ public class FlipDrawable extends LayerDrawable implements ValueAnimator.Animato
private float mRotate;
public FlipDrawable(Drawable from, Drawable to) {
- super(new Drawable[] { from, to });
+ super(new Drawable[]{from, to});
mFrom = from;
mTo = to;
mCamera = new Camera();
@@ -45,8 +24,8 @@ public FlipDrawable(Drawable from, Drawable to) {
@Override
public void draw(Canvas canvas) {
- float centerX = getIntrinsicWidth()/2;
- float centerY = getIntrinsicHeight()/2;
+ float centerX = getIntrinsicWidth() / 2;
+ float centerY = getIntrinsicHeight() / 2;
boolean flipped = mRotate > 90;
mCamera.save();
mCamera.translate(centerX, centerY, 0);
@@ -71,10 +50,6 @@ public Drawable getCurrent() {
return mRotate > 90 ? mTo : mFrom;
}
- /**
- * Starts the flip animation.
- * @param duration The duration in ms for the flip to occur.
- */
public void start(long duration) {
ValueAnimator animator = ValueAnimator.ofFloat(0, 180);
animator.setDuration(duration);
diff --git a/app/src/main/java/com/terracom/qrpttbeta/preference/KeySelectDialogPreference.java b/app/src/main/java/com/terracom/qrpttbeta/preference/KeySelectDialogPreference.java
old mode 100644
new mode 100755
index 80871de3..9cdb1644
--- a/app/src/main/java/com/terracom/qrpttbeta/preference/KeySelectDialogPreference.java
+++ b/app/src/main/java/com/terracom/qrpttbeta/preference/KeySelectDialogPreference.java
@@ -1,20 +1,3 @@
-/*
- * Copyright (C) 2014 Andrew Comminos
- *
- * This program 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 .
- */
-
package com.terracom.qrpttbeta.preference;
import android.annotation.TargetApi;
@@ -36,110 +19,108 @@
import com.terracom.qrpttbeta.R;
public class KeySelectDialogPreference extends DialogPreference implements OnKeyListener {
-
- //private static final String ANDROID_NAMESPACE = "http://schemas.android.com/apk/res/android";
-
- private TextView valueTextView;
- private int keyCode;
-
- public KeySelectDialogPreference(Context context, AttributeSet attrs) {
- super(context, attrs);
- }
-
- @Override
- protected void onPrepareDialogBuilder(Builder builder) {
- super.onPrepareDialogBuilder(builder);
-
- builder.setOnKeyListener(this);
- builder.setNeutralButton(R.string.reset_key, new OnClickListener() {
-
- @Override
- public void onClick(DialogInterface dialog, int which) {
- keyCode = 0;
- valueTextView.setText("No Key");
- persistInt(keyCode); // Neutral is a 'negative' response to android, we save manually here.
- }
- });
- }
-
- @Override
- protected View onCreateDialogView() {
- LinearLayout.LayoutParams params = new LinearLayout.LayoutParams(LayoutParams.MATCH_PARENT, LayoutParams.WRAP_CONTENT);
- LinearLayout layout = new LinearLayout(getContext());
- layout.setOrientation(LinearLayout.VERTICAL);
- layout.setPadding(6,6,6,6);
-
- TextView promptTextView = new TextView(getContext());
- promptTextView.setText(R.string.pressKey);
- promptTextView.setGravity(Gravity.CENTER_HORIZONTAL);
-
- valueTextView = new TextView(getContext());
- valueTextView.setTextSize(TypedValue.COMPLEX_UNIT_SP, 22);
- valueTextView.setGravity(Gravity.CENTER_HORIZONTAL);
- valueTextView.setPadding(0, 12, 0, 12);
-
- TextView alertTextView = new TextView(getContext());
- alertTextView.setText(R.string.pressKeyInfo);
- alertTextView.setGravity(Gravity.CENTER_HORIZONTAL);
- alertTextView.setTextSize(TypedValue.COMPLEX_UNIT_SP, 12);
-
- layout.addView(promptTextView, params);
- layout.addView(valueTextView, params);
- layout.addView(alertTextView);
-
- return layout;
- }
-
- @Override
- protected void onSetInitialValue(boolean restorePersistedValue,
- Object defaultValue) {
- super.onSetInitialValue(restorePersistedValue, defaultValue);
- if(restorePersistedValue) {
- keyCode = getPersistedInt(0);
- } else {
- keyCode = (Integer)defaultValue;
- }
- }
-
- @Override
- protected void onDialogClosed(boolean positiveResult) {
- if(positiveResult) {
- persistInt(keyCode);
- }
-
- super.onDialogClosed(positiveResult);
- }
-
- @TargetApi(12)
- @Override
- protected void onBindDialogView(View view) {
- super.onBindDialogView(view);
- if(keyCode == 0) {
- valueTextView.setText("No Key");
- } else {
- if(android.os.Build.VERSION.SDK_INT >= 12) {
- valueTextView.setText(KeyEvent.keyCodeToString(keyCode));
- } else {
- valueTextView.setText("Key code: "+keyCode);
- }
- }
- }
-
- @TargetApi(12)
- @Override
- public boolean onKey(DialogInterface dialog, int keyCode, KeyEvent event) {
- if(keyCode != KeyEvent.KEYCODE_BACK) {
- this.keyCode = keyCode;
-
- if(android.os.Build.VERSION.SDK_INT >= 12) {
- valueTextView.setText(KeyEvent.keyCodeToString(keyCode));
- } else {
- valueTextView.setText("Key code: "+keyCode);
- }
- } else {
- dialog.dismiss();
- }
- return true;
- }
+
+ private TextView valueTextView;
+ private int keyCode;
+
+ public KeySelectDialogPreference(Context context, AttributeSet attrs) {
+ super(context, attrs);
+ }
+
+ @Override
+ protected void onPrepareDialogBuilder(Builder builder) {
+ super.onPrepareDialogBuilder(builder);
+
+ builder.setOnKeyListener(this);
+ builder.setNeutralButton(R.string.reset_key, new OnClickListener() {
+
+ @Override
+ public void onClick(DialogInterface dialog, int which) {
+ keyCode = 0;
+ valueTextView.setText("No Key");
+ persistInt(keyCode);
+ }
+ });
+ }
+
+ @Override
+ protected View onCreateDialogView() {
+ LinearLayout.LayoutParams params = new LinearLayout.LayoutParams(LayoutParams.MATCH_PARENT, LayoutParams.WRAP_CONTENT);
+ LinearLayout layout = new LinearLayout(getContext());
+ layout.setOrientation(LinearLayout.VERTICAL);
+ layout.setPadding(6, 6, 6, 6);
+
+ TextView promptTextView = new TextView(getContext());
+ promptTextView.setText(R.string.pressKey);
+ promptTextView.setGravity(Gravity.CENTER_HORIZONTAL);
+
+ valueTextView = new TextView(getContext());
+ valueTextView.setTextSize(TypedValue.COMPLEX_UNIT_SP, 22);
+ valueTextView.setGravity(Gravity.CENTER_HORIZONTAL);
+ valueTextView.setPadding(0, 12, 0, 12);
+
+ TextView alertTextView = new TextView(getContext());
+ alertTextView.setText(R.string.pressKeyInfo);
+ alertTextView.setGravity(Gravity.CENTER_HORIZONTAL);
+ alertTextView.setTextSize(TypedValue.COMPLEX_UNIT_SP, 12);
+
+ layout.addView(promptTextView, params);
+ layout.addView(valueTextView, params);
+ layout.addView(alertTextView);
+
+ return layout;
+ }
+
+ @Override
+ protected void onSetInitialValue(boolean restorePersistedValue,
+ Object defaultValue) {
+ super.onSetInitialValue(restorePersistedValue, defaultValue);
+ if (restorePersistedValue) {
+ keyCode = getPersistedInt(0);
+ } else {
+ keyCode = (Integer) defaultValue;
+ }
+ }
+
+ @Override
+ protected void onDialogClosed(boolean positiveResult) {
+ if (positiveResult) {
+ persistInt(keyCode);
+ }
+
+ super.onDialogClosed(positiveResult);
+ }
+
+ @TargetApi(12)
+ @Override
+ protected void onBindDialogView(View view) {
+ super.onBindDialogView(view);
+ if (keyCode == 0) {
+ valueTextView.setText("No Key");
+ } else {
+ if (android.os.Build.VERSION.SDK_INT >= 12) {
+ valueTextView.setText(KeyEvent.keyCodeToString(keyCode));
+ } else {
+ valueTextView.setText("Key code: " + keyCode);
+ }
+ }
+ }
+
+ @TargetApi(12)
+ @Override
+ public boolean onKey(DialogInterface dialog, int keyCode, KeyEvent event) {
+ if (keyCode != KeyEvent.KEYCODE_BACK) {
+ this.keyCode = keyCode;
+
+ if (android.os.Build.VERSION.SDK_INT >= 12) {
+ valueTextView.setText(KeyEvent.keyCodeToString(keyCode));
+ } else {
+ valueTextView.setText("Key code: " + keyCode);
+ }
+ } else {
+ dialog.dismiss();
+ }
+ return true;
+ }
}
diff --git a/app/src/main/java/com/terracom/qrpttbeta/preference/Preferences.java b/app/src/main/java/com/terracom/qrpttbeta/preference/Preferences.java
old mode 100644
new mode 100755
index 2ab5d8e7..c6f2741f
--- a/app/src/main/java/com/terracom/qrpttbeta/preference/Preferences.java
+++ b/app/src/main/java/com/terracom/qrpttbeta/preference/Preferences.java
@@ -1,27 +1,9 @@
-/*
- * Copyright (C) 2014 Andrew Comminos
- *
- * This program 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 .
- */
-
package com.terracom.qrpttbeta.preference;
import android.annotation.TargetApi;
import android.app.AlertDialog;
import android.content.Context;
import android.content.DialogInterface;
-import android.content.Intent;
import android.content.SharedPreferences;
import android.content.pm.PackageInfo;
import android.content.pm.PackageManager;
@@ -38,14 +20,11 @@
import android.preference.PreferenceFragment;
import android.preference.PreferenceScreen;
import android.text.InputType;
-import android.util.Log;
import android.widget.EditText;
import android.widget.Toast;
import com.terracom.qrpttbeta.R;
import com.terracom.qrpttbeta.Settings;
-import com.terracom.qrpttbeta.app.DrawerAdapter;
-import com.terracom.qrpttbeta.app.QRPushToTalkActivity;
import com.terracom.qrpttbeta.util.QRPushToTalkTrustStore;
import java.io.File;
@@ -56,10 +35,6 @@
import info.guardianproject.onionkit.ui.OrbotHelper;
-/**
- * This entire class is a mess.
- * FIXME. Please.
- */
public class Preferences extends PreferenceActivity {
public static final String ACTION_PREFS_GENERAL = "com.terracom.qrpttbeta.app.PREFS_GENERAL";
@@ -78,8 +53,6 @@ public class Preferences extends PreferenceActivity {
protected void onCreate(final Bundle savedInstanceState) {
super.onCreate(savedInstanceState);
- // Legacy preference section handling
-
String action = getIntent().getAction();
if (action != null) {
if (ACTION_PREFS_GENERAL.equals(action)) {
@@ -128,20 +101,16 @@ public boolean onPreferenceClick(Preference preference) {
certificatePathPreference.setOnPreferenceChangeListener(new Preference.OnPreferenceChangeListener() {
@Override
public boolean onPreferenceChange(Preference preference, Object newValue) {
- // Unset password
SharedPreferences preferences = preference.getSharedPreferences();
preferences.edit()
.putString(Settings.PREF_CERT_PASSWORD, "")
.commit();
- if("".equals(newValue)) return true; // No certificate
- File cert = new File((String)newValue);
+ if ("".equals(newValue)) return true;
+ File cert = new File((String) newValue);
try {
boolean needsPassword = QRPushToTalkCertificateManager.isPasswordRequired(cert);
- if(!needsPassword) return true;
-
- // If we need a password, prompt the user. Do NOT change the preference until
- // the password has been provided.
+ if (!needsPassword) return true;
promptCertificatePassword(preference.getContext(), (ListPreference) preference, cert);
} catch (Exception e) {
@@ -160,7 +129,6 @@ public boolean onPreferenceClick(Preference preference) {
}
});
- // Make sure media is mounted, otherwise do not allow certificate loading.
if (Environment.getExternalStorageState().equals(Environment.MEDIA_MOUNTED)) {
try {
updateCertificatePath(certificatePathPreference);
@@ -174,10 +142,6 @@ public boolean onPreferenceClick(Preference preference) {
}
}
- /**
- * Prompts the user for the given certificate's password, setting the certificate as
- * active if the password is correct.
- */
private static void promptCertificatePassword(final Context context, final ListPreference certificatePreference, final File certificate) {
AlertDialog.Builder adb = new AlertDialog.Builder(context);
adb.setTitle(R.string.certificatePassword);
@@ -200,7 +164,7 @@ public void onClick(DialogInterface dialog, int which) {
} catch (NoSuchAlgorithmException e) {
e.printStackTrace();
} finally {
- if(passwordValid) {
+ if (passwordValid) {
certificatePreference.setValue(certificate.getAbsolutePath());
certificatePreference.getSharedPreferences().edit()
.putString(Settings.PREF_CERT_PASSWORD, password)
@@ -232,13 +196,12 @@ public boolean onPreferenceChange(Preference preference, Object newValue) {
}
});
- // Scan each bitrate and determine if the device supports it
ListPreference inputQualityPreference = (ListPreference) screen.findPreference(Settings.PREF_INPUT_RATE);
String[] bitrateNames = new String[inputQualityPreference.getEntryValues().length];
- for(int x=0;x 0;
- bitrateNames[x] = bitrate+"Hz" + (supported ? "" : " (unsupported)");
+ bitrateNames[x] = bitrate + "Hz" + (supported ? "" : " (unsupported)");
}
inputQualityPreference.setEntries(bitrateNames);
@@ -248,21 +211,13 @@ public boolean onPreferenceChange(Preference preference, Object newValue) {
private static void updateAudioDependents(PreferenceScreen screen, String inputMethod) {
PreferenceCategory pttCategory = (PreferenceCategory) screen.findPreference("ptt_settings");
PreferenceCategory vadCategory = (PreferenceCategory) screen.findPreference("vad_settings");
-// pttCategory.setEnabled(Settings.ARRAY_INPUT_METHOD_PTT.equals(inputMethod));
pttCategory.setEnabled(true);
-// vadCategory.setEnabled(Settings.ARRAY_INPUT_METHOD_VOICE.equals(inputMethod));
vadCategory.setEnabled(false);
}
- /**
- * Updates the passed preference with the certificate paths found on external storage.
- *
- * @param preference The ListPreference to update.
- */
private static void updateCertificatePath(ListPreference preference) throws NullPointerException, IOException {
List certificateFiles = QRPushToTalkCertificateManager.getAvailableCertificates();
- // Get arrays of certificate paths and names.
String[] certificateNames = new String[certificateFiles.size() + 1]; // Extra space for 'None' option
String[] certificatePaths = new String[certificateFiles.size() + 1];
for (int x = 0; x < certificateFiles.size(); x++) {
@@ -277,11 +232,6 @@ private static void updateCertificatePath(ListPreference preference) throws Null
preference.setEntryValues(certificatePaths);
}
- /**
- * Generates a new certificate and sets it as active.
- *
- * @param certificateList If passed, will update the list of certificates available. Messy.
- */
private static void generateCertificate(final ListPreference certificateList) {
QRPushToTalkCertificateGenerateTask generateTask = new QRPushToTalkCertificateGenerateTask(certificateList.getContext()) {
@Override
@@ -290,7 +240,7 @@ protected void onPostExecute(File result) {
if (result != null) {
try {
- updateCertificatePath(certificateList); // Update cert path after
+ updateCertificatePath(certificateList);
certificateList.setValue(result.getAbsolutePath());
} catch (IOException e) {
e.printStackTrace();
diff --git a/app/src/main/java/com/terracom/qrpttbeta/preference/QRPushToTalkCertificateGenerateTask.java b/app/src/main/java/com/terracom/qrpttbeta/preference/QRPushToTalkCertificateGenerateTask.java
old mode 100644
new mode 100755
index a049f08a..0abe8914
--- a/app/src/main/java/com/terracom/qrpttbeta/preference/QRPushToTalkCertificateGenerateTask.java
+++ b/app/src/main/java/com/terracom/qrpttbeta/preference/QRPushToTalkCertificateGenerateTask.java
@@ -1,20 +1,3 @@
-/*
- * Copyright (C) 2014 Andrew Comminos
- *
- * This program 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 .
- */
-
package com.terracom.qrpttbeta.preference;
import android.app.ProgressDialog;
@@ -29,50 +12,51 @@
import java.io.File;
public class QRPushToTalkCertificateGenerateTask extends AsyncTask {
-
- private Context context;
- private ProgressDialog loadingDialog;
-
- public QRPushToTalkCertificateGenerateTask(Context context) {
- this.context = context;
- }
-
- @Override
- protected void onPreExecute() {
- super.onPreExecute();
-
- loadingDialog = new ProgressDialog(context);
- loadingDialog.setIndeterminate(true);
- loadingDialog.setMessage(context.getString(R.string.generateCertProgress));
- loadingDialog.setOnCancelListener(new OnCancelListener() {
-
- @Override
- public void onCancel(DialogInterface arg0) {
- cancel(true);
-
- }
- });
- loadingDialog.show();
- }
- @Override
- protected File doInBackground(Void... params) {
- try {
- return QRPushToTalkCertificateManager.generateCertificate();
- } catch (Exception e) {
- e.printStackTrace();
- return null;
- }
- }
-
- @Override
- protected void onPostExecute(File result) {
- super.onPostExecute(result);
- if(result != null) {
- Toast.makeText(context, context.getString(R.string.generateCertSuccess, result.getName()), Toast.LENGTH_SHORT).show();
- } else {
- Toast.makeText(context, R.string.generateCertFailure, Toast.LENGTH_SHORT).show();
- }
-
- loadingDialog.dismiss();
- }
+
+ private Context context;
+ private ProgressDialog loadingDialog;
+
+ public QRPushToTalkCertificateGenerateTask(Context context) {
+ this.context = context;
+ }
+
+ @Override
+ protected void onPreExecute() {
+ super.onPreExecute();
+
+ loadingDialog = new ProgressDialog(context);
+ loadingDialog.setIndeterminate(true);
+ loadingDialog.setMessage(context.getString(R.string.generateCertProgress));
+ loadingDialog.setOnCancelListener(new OnCancelListener() {
+
+ @Override
+ public void onCancel(DialogInterface arg0) {
+ cancel(true);
+
+ }
+ });
+ loadingDialog.show();
+ }
+
+ @Override
+ protected File doInBackground(Void... params) {
+ try {
+ return QRPushToTalkCertificateManager.generateCertificate();
+ } catch (Exception e) {
+ e.printStackTrace();
+ return null;
+ }
+ }
+
+ @Override
+ protected void onPostExecute(File result) {
+ super.onPostExecute(result);
+ if (result != null) {
+ Toast.makeText(context, context.getString(R.string.generateCertSuccess, result.getName()), Toast.LENGTH_SHORT).show();
+ } else {
+ Toast.makeText(context, R.string.generateCertFailure, Toast.LENGTH_SHORT).show();
+ }
+
+ loadingDialog.dismiss();
+ }
}
diff --git a/app/src/main/java/com/terracom/qrpttbeta/preference/QRPushToTalkCertificateManager.java b/app/src/main/java/com/terracom/qrpttbeta/preference/QRPushToTalkCertificateManager.java
old mode 100644
new mode 100755
index 38817d42..341988fc
--- a/app/src/main/java/com/terracom/qrpttbeta/preference/QRPushToTalkCertificateManager.java
+++ b/app/src/main/java/com/terracom/qrpttbeta/preference/QRPushToTalkCertificateManager.java
@@ -1,20 +1,3 @@
-/*
- * Copyright (C) 2014 Andrew Comminos
- *
- * This program 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 .
- */
-
package com.terracom.qrpttbeta.preference;
import android.os.Environment;
@@ -41,15 +24,10 @@
public class QRPushToTalkCertificateManager {
- private static final String CERTIFICATE_FOLDER = "QRPushToTalk";
- private static final String CERTIFICATE_FORMAT = "qrptt-%s.p12";
+ private static final String CERTIFICATE_FOLDER = "QRPushToTalk";
+ private static final String CERTIFICATE_FORMAT = "qrptt-%s.p12";
private static final SimpleDateFormat DATE_FORMAT = new SimpleDateFormat("yyyy-MM-dd_HH-mm-ss");
-
- /**
- * Generates a new X.509 passwordless certificate in PKCS12 format for connection to a Mumble server.
- * This certificate is stored in the {@value #CERTIFICATE_FOLDER} folder on the external storage, in the format {@value #CERTIFICATE_FORMAT} where the timestamp is substituted in.
- * @return The path of the generated certificate if the operation was a success. Otherwise, null.
- */
+
public static File generateCertificate() throws NoSuchAlgorithmException, OperatorCreationException, CertificateException, KeyStoreException, NoSuchProviderException, IOException {
File certificateDirectory = getCertificateDirectory();
@@ -61,29 +39,20 @@ public static File generateCertificate() throws NoSuchAlgorithmException, Operat
return certificateFile;
}
- /**
- * Returns a list of certificates in the {@value #CERTIFICATE_FOLDER} folder on external storage, ending with pfx or p12.
- * @return A list of {@link File} objects containing certificates.
- */
- public static List getAvailableCertificates() throws IOException {
- File certificateDirectory = getCertificateDirectory();
-
- File[] p12Files = certificateDirectory.listFiles(new FileFilter() {
- @Override
- public boolean accept(File pathname) {
- return pathname.getName().endsWith("pfx") ||
- pathname.getName().endsWith("p12");
- }
- });
-
- return Arrays.asList(p12Files);
- }
+ public static List getAvailableCertificates() throws IOException {
+ File certificateDirectory = getCertificateDirectory();
+
+ File[] p12Files = certificateDirectory.listFiles(new FileFilter() {
+ @Override
+ public boolean accept(File pathname) {
+ return pathname.getName().endsWith("pfx") ||
+ pathname.getName().endsWith("p12");
+ }
+ });
+
+ return Arrays.asList(p12Files);
+ }
- /**
- * Checks to see if the certificate at the given path is password protected.
- * @param certificateFile A PKCS12 certificate.
- * @return true if the certificate is password protected, false otherwise.
- */
public static boolean isPasswordRequired(File certificateFile) throws KeyStoreException, IOException, NoSuchAlgorithmException {
KeyStore p12store = KeyStore.getInstance("PKCS12");
FileInputStream inputStream = new FileInputStream(certificateFile);
@@ -99,12 +68,6 @@ public static boolean isPasswordRequired(File certificateFile) throws KeyStoreEx
}
}
- /**
- * Checks to see if the certificate at the given path is password protected.
- * @param certificateFile A PKCS12 certificate.
- * @param password A password for the certificate.
- * @return true if the password is valid, false otherwise.
- */
public static boolean isPasswordValid(File certificateFile, String password) throws KeyStoreException, IOException, NoSuchAlgorithmException {
KeyStore p12store = KeyStore.getInstance("PKCS12");
FileInputStream inputStream = new FileInputStream(certificateFile);
@@ -117,19 +80,14 @@ public static boolean isPasswordValid(File certificateFile, String password) thr
}
}
- /**
- * Returns the certificate directory, {@value #PLUMBLE_CERTIFICATE_FOLDER}, on external storage.
- * Will create if does not exist, and throw an assert if the external storage is not mounted.
- * @return The {@link File} object of the directory.
- */
- public static File getCertificateDirectory() throws IOException {
- if(Environment.getExternalStorageState().equals(Environment.MEDIA_MOUNTED)) {
+ public static File getCertificateDirectory() throws IOException {
+ if (Environment.getExternalStorageState().equals(Environment.MEDIA_MOUNTED)) {
File certificateDirectory = new File(Environment.getExternalStorageDirectory(), CERTIFICATE_FOLDER);
- if(!certificateDirectory.exists())
+ if (!certificateDirectory.exists())
certificateDirectory.mkdir();
return certificateDirectory;
} else {
throw new IOException("External storage not available.");
}
- }
+ }
}
diff --git a/app/src/main/java/com/terracom/qrpttbeta/preference/SeekBarDialogPreference.java b/app/src/main/java/com/terracom/qrpttbeta/preference/SeekBarDialogPreference.java
old mode 100644
new mode 100755
index d075651a..5f4af8a3
--- a/app/src/main/java/com/terracom/qrpttbeta/preference/SeekBarDialogPreference.java
+++ b/app/src/main/java/com/terracom/qrpttbeta/preference/SeekBarDialogPreference.java
@@ -1,28 +1,3 @@
-/*
- * Copyright (C) 2014 Andrew Comminos
- *
- * This program 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 .
- */
-
-/* The following code was written by Matthew Wiggins
- * and is released under the Apache 2.0 license
- *
- * http://www.apache.org/licenses/LICENSE-2.0
- *
- * I added some extra functionality like a multiplier + better persistence.
- * - Andrew Comminos
- */
package com.terracom.qrpttbeta.preference;
import android.content.Context;
@@ -115,9 +90,6 @@ public void onStartTrackingTouch(SeekBar seek) {
public void onStopTrackingTouch(SeekBar seek) {
}
- /* (non-Javadoc)
- * @see android.preference.DialogPreference#onDialogClosed(boolean)
- */
@Override
protected void onDialogClosed(boolean positiveResult) {
super.onDialogClosed(positiveResult);
diff --git a/app/src/main/java/com/terracom/qrpttbeta/servers/FavouriteServerAdapter.java b/app/src/main/java/com/terracom/qrpttbeta/servers/FavouriteServerAdapter.java
old mode 100644
new mode 100755
index b7716713..1a36b0f0
--- a/app/src/main/java/com/terracom/qrpttbeta/servers/FavouriteServerAdapter.java
+++ b/app/src/main/java/com/terracom/qrpttbeta/servers/FavouriteServerAdapter.java
@@ -1,20 +1,3 @@
-/*
- * Copyright (C) 2014 Andrew Comminos
- *
- * This program 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 .
- */
-
package com.terracom.qrpttbeta.servers;
import android.content.Context;
@@ -22,7 +5,6 @@
import com.terracom.jumble.model.Server;
import com.terracom.qrpttbeta.R;
-import com.terracom.qrpttbeta.app.QRPushToTalkActivity;
import java.util.List;
@@ -50,9 +32,6 @@ public boolean onPopupItemClick(Server server, MenuItem menuItem) {
case R.id.menu_server_edit:
mListener.editServer(server);
return true;
- /*case R.id.menu_server_share:
- mListener.shareServer(server);
- return true;*/
case R.id.menu_server_delete:
mListener.deleteServer(server);
return true;
@@ -63,7 +42,7 @@ public boolean onPopupItemClick(Server server, MenuItem menuItem) {
public static interface FavouriteServerAdapterMenuListener {
public void editServer(Server server);
- public void shareServer(Server server);
+
public void deleteServer(Server server);
}
}
diff --git a/app/src/main/java/com/terracom/qrpttbeta/servers/FavouriteServerListFragment.java b/app/src/main/java/com/terracom/qrpttbeta/servers/FavouriteServerListFragment.java
old mode 100644
new mode 100755
index 7c3d14c2..b3ad6368
--- a/app/src/main/java/com/terracom/qrpttbeta/servers/FavouriteServerListFragment.java
+++ b/app/src/main/java/com/terracom/qrpttbeta/servers/FavouriteServerListFragment.java
@@ -1,20 +1,3 @@
-/*
- * Copyright (C) 2014 Andrew Comminos
- *
- * This program 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 .
- */
-
package com.terracom.qrpttbeta.servers;
import android.app.Activity;
@@ -40,11 +23,6 @@
import java.util.List;
-/**
- * Displays a list of servers, and allows the user to connect and edit them.
- * @author terracom
- *
- */
public class FavouriteServerListFragment extends Fragment implements OnItemClickListener, FavouriteServerAdapter.FavouriteServerAdapterMenuListener {
private ServerConnectHandler mConnectHandler;
@@ -64,10 +42,10 @@ public void onAttach(Activity activity) {
super.onAttach(activity);
try {
- mConnectHandler = (ServerConnectHandler)activity;
+ mConnectHandler = (ServerConnectHandler) activity;
mDatabaseProvider = (DatabaseProvider) activity;
} catch (ClassCastException e) {
- throw new ClassCastException(activity.toString()+" must implement ServerConnectHandler!");
+ throw new ClassCastException(activity.toString() + " must implement ServerConnectHandler!");
}
}
@@ -78,17 +56,6 @@ public View onCreateView(LayoutInflater inflater, ViewGroup container,
mServerGrid = (GridView) view.findViewById(R.id.server_list_grid);
mServerGrid.setOnItemClickListener(this);
mServerGrid.setEmptyView(view.findViewById(R.id.server_list_grid_empty));
-
- /*TextView donateText = (TextView) view.findViewById(R.id.donate_box);
- donateText.setVisibility(BuildConfig.DONATE_NAG ? View.VISIBLE : View.GONE);
- donateText.setOnClickListener(new OnClickListener() {
- @Override
- public void onClick(View v) {
- Intent playIntent = new Intent(Intent.ACTION_VIEW, Uri.parse("market://details?id=com.terracom.qrpttbeta"));
- startActivity(playIntent);
- }
- });*/
-
registerForContextMenu(mServerGrid);
return view;
}
@@ -107,7 +74,7 @@ public void onResume() {
@Override
public boolean onOptionsItemSelected(MenuItem item) {
- if(item.getItemId() == R.id.menu_add_server_item) {
+ if (item.getItemId() == R.id.menu_add_server_item) {
addServer();
return true;
}
@@ -128,21 +95,10 @@ public void editServer(Server server) {
setEditedUsernameFlag(true);
}
- public static void setEditedUsernameFlag(boolean myflag){
+ public static void setEditedUsernameFlag(boolean myflag) {
myEditedflag = myflag;
}
- public void shareServer(Server server) {
- // Build Mumble server URL
- String serverUrl = "mumble://"+server.getHost()+":"+server.getPort()+"/";
-
- Intent intent = new Intent();
- intent.setAction(Intent.ACTION_SEND);
- intent.putExtra(Intent.EXTRA_TEXT, getString(R.string.shareMessage, serverUrl));
- intent.setType("text/plain");
- startActivity(intent);
- }
-
public void deleteServer(final Server server) {
AlertDialog.Builder alertBuilder = new AlertDialog.Builder(getActivity());
alertBuilder.setMessage(R.string.confirm_delete_server);
@@ -163,8 +119,6 @@ public void updateServers() {
mServerGrid.setAdapter(mServerAdapter);
}
-
-
public List getServers() {
List servers = mDatabaseProvider.getDatabase().getServers();
return servers;
@@ -177,6 +131,7 @@ public void onItemClick(AdapterView> arg0, View arg1, int arg2, long arg3) {
public static interface ServerConnectHandler {
public void connectToServer(Server server);
+
public void connectToPublicServer(PublicServer server);
}
}
diff --git a/app/src/main/java/com/terracom/qrpttbeta/servers/HttpRequest.java b/app/src/main/java/com/terracom/qrpttbeta/servers/HttpRequest.java
old mode 100644
new mode 100755
index 012a3ef6..71979026
--- a/app/src/main/java/com/terracom/qrpttbeta/servers/HttpRequest.java
+++ b/app/src/main/java/com/terracom/qrpttbeta/servers/HttpRequest.java
@@ -1,54 +1,18 @@
-/*
- * Copyright (c) 2014 Kevin Sawicki
- *
- * Permission is hereby granted, free of charge, to any person obtaining a copy
- * of this software and associated documentation files (the "Software"), to
- * deal in the Software without restriction, including without limitation the
- * rights to use, copy, modify, merge, publish, distribute, sublicense, and/or
- * sell copies of the Software, and to permit persons to whom the Software is
- * furnished to do so, subject to the following conditions:
- *
- * The above copyright notice and this permission notice shall be included in
- * all copies or substantial portions of the Software.
- *
- * THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
- * IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
- * FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
- * AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
- * LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING
- * FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS
- * IN THE SOFTWARE.
- */
package com.terracom.qrpttbeta.servers;
import static java.net.HttpURLConnection.HTTP_BAD_REQUEST;
-import static java.net.HttpURLConnection.HTTP_CREATED;
-import static java.net.HttpURLConnection.HTTP_INTERNAL_ERROR;
-import static java.net.HttpURLConnection.HTTP_NO_CONTENT;
-import static java.net.HttpURLConnection.HTTP_NOT_FOUND;
-import static java.net.HttpURLConnection.HTTP_NOT_MODIFIED;
-import static java.net.HttpURLConnection.HTTP_OK;
import static java.net.Proxy.Type.HTTP;
import java.io.BufferedInputStream;
import java.io.BufferedOutputStream;
-import java.io.BufferedReader;
import java.io.ByteArrayInputStream;
import java.io.ByteArrayOutputStream;
import java.io.Closeable;
-import java.io.File;
-import java.io.FileInputStream;
-import java.io.FileNotFoundException;
-import java.io.FileOutputStream;
import java.io.Flushable;
import java.io.IOException;
import java.io.InputStream;
-import java.io.InputStreamReader;
import java.io.OutputStream;
-import java.io.OutputStreamWriter;
-import java.io.PrintStream;
import java.io.Reader;
-import java.io.UnsupportedEncodingException;
import java.io.Writer;
import java.net.HttpURLConnection;
import java.net.InetSocketAddress;
@@ -57,27 +21,20 @@
import java.net.URI;
import java.net.URISyntaxException;
import java.net.URL;
-import java.net.URLEncoder;
import java.nio.ByteBuffer;
import java.nio.CharBuffer;
import java.nio.charset.Charset;
import java.nio.charset.CharsetEncoder;
-import java.security.AccessController;
import java.security.GeneralSecurityException;
-import java.security.PrivilegedAction;
import java.security.SecureRandom;
import java.security.cert.X509Certificate;
import java.util.ArrayList;
import java.util.Arrays;
-import java.util.Collections;
import java.util.Iterator;
-import java.util.LinkedHashMap;
import java.util.List;
import java.util.Map;
import java.util.Map.Entry;
import java.util.concurrent.Callable;
-import java.util.concurrent.atomic.AtomicInteger;
-import java.util.concurrent.atomic.AtomicReference;
import java.util.zip.GZIPInputStream;
import javax.net.ssl.HostnameVerifier;
@@ -88,3172 +45,627 @@
import javax.net.ssl.TrustManager;
import javax.net.ssl.X509TrustManager;
-/**
- * A fluid interface for making HTTP requests using an underlying
- * {@link java.net.HttpURLConnection} (or sub-class).
- *