diff options
author | Artur Dryomov <artur.dryomov@gmail.com> | 2013-09-14 15:02:47 +0300 |
---|---|---|
committer | Artur Dryomov <artur.dryomov@gmail.com> | 2013-09-14 19:38:44 +0300 |
commit | 2436d8c9bc296d64a98c6b1bcbecb66d42f15aab (patch) | |
tree | 8d20dfae1022fadd367f24033145a5f46a8269a2 /android | |
parent | fff70bf98c7a5a63aa0db11e93a3512c6a9a9359 (diff) |
Fix another code style issues.
Change-Id: Id76d17050b7fc2865a78b9a815a2f543e85e321f
Diffstat (limited to 'android')
15 files changed, 114 insertions, 116 deletions
diff --git a/android/sdremote/src/org/libreoffice/impressremote/activity/ComputerConnectionActivity.java b/android/sdremote/src/org/libreoffice/impressremote/activity/ComputerConnectionActivity.java index fda1d96d232f..f68c43c977cc 100644 --- a/android/sdremote/src/org/libreoffice/impressremote/activity/ComputerConnectionActivity.java +++ b/android/sdremote/src/org/libreoffice/impressremote/activity/ComputerConnectionActivity.java @@ -14,7 +14,7 @@ import android.support.v4.app.Fragment; import com.actionbarsherlock.app.SherlockFragmentActivity; import com.actionbarsherlock.view.MenuItem; import org.libreoffice.impressremote.fragment.ComputerConnectionFragment; -import org.libreoffice.impressremote.util.FragmentOperator; +import org.libreoffice.impressremote.util.Fragments; import org.libreoffice.impressremote.util.Intents; import org.libreoffice.impressremote.communication.Server; @@ -33,20 +33,20 @@ public class ComputerConnectionActivity extends SherlockFragmentActivity { } private void setUpTitle() { - String aComputerName = extractReceivedComputer().getName(); + String aComputerName = getComputer().getName(); getSupportActionBar().setSubtitle(aComputerName); } - private Server extractReceivedComputer() { + private Server getComputer() { return getIntent().getParcelableExtra(Intents.Extras.SERVER); } private void setUpFragment() { - Server aComputer = extractReceivedComputer(); + Server aComputer = getComputer(); Fragment aFragment = ComputerConnectionFragment.newInstance(aComputer); - FragmentOperator.addFragment(this, aFragment); + Fragments.Operator.add(this, aFragment); } @Override diff --git a/android/sdremote/src/org/libreoffice/impressremote/activity/ComputerCreationActivity.java b/android/sdremote/src/org/libreoffice/impressremote/activity/ComputerCreationActivity.java index 4e91251ef498..0ccf0e9f6f81 100644 --- a/android/sdremote/src/org/libreoffice/impressremote/activity/ComputerCreationActivity.java +++ b/android/sdremote/src/org/libreoffice/impressremote/activity/ComputerCreationActivity.java @@ -89,8 +89,7 @@ public class ComputerCreationActivity extends SherlockFragmentActivity implement String aName = getText(getNameEdit()); if (!isIpAddressValid(aIpAddress)) { - getIpAddressEdit().setError(getText(R.string.message_ip_address_validation)); - getIpAddressEdit().requestFocus(); + setUpIpAddressErrorMessage(); return; } @@ -117,6 +116,13 @@ public class ComputerCreationActivity extends SherlockFragmentActivity implement return Patterns.IP_ADDRESS.matcher(aIpAddress).matches(); } + private void setUpIpAddressErrorMessage() { + EditText aIpAddressEdit = getIpAddressEdit(); + + aIpAddressEdit.setError(getString(R.string.message_ip_address_validation)); + aIpAddressEdit.requestFocus(); + } + private void finish(String aIpAddress, String aName) { Intent aIntent = Intents.buildComputerCreationResultIntent(aIpAddress, aName); setResult(Activity.RESULT_OK, aIntent); diff --git a/android/sdremote/src/org/libreoffice/impressremote/activity/ComputersActivity.java b/android/sdremote/src/org/libreoffice/impressremote/activity/ComputersActivity.java index 954c9fc4ecf8..7b085e75ab3c 100644 --- a/android/sdremote/src/org/libreoffice/impressremote/activity/ComputersActivity.java +++ b/android/sdremote/src/org/libreoffice/impressremote/activity/ComputersActivity.java @@ -22,7 +22,7 @@ import com.actionbarsherlock.view.MenuItem; import org.libreoffice.impressremote.adapter.ComputersPagerAdapter; import org.libreoffice.impressremote.fragment.ComputersFragment; import org.libreoffice.impressremote.util.BluetoothOperator; -import org.libreoffice.impressremote.util.FragmentOperator; +import org.libreoffice.impressremote.util.Fragments; import org.libreoffice.impressremote.util.Intents; import org.libreoffice.impressremote.R; import org.libreoffice.impressremote.util.Preferences; @@ -153,7 +153,7 @@ public class ComputersActivity extends SherlockFragmentActivity implements Actio private void setUpComputersList() { Fragment aComputersFragment = ComputersFragment.newInstance(ComputersFragment.Type.WIFI); - FragmentOperator.addFragment(this, aComputersFragment); + Fragments.Operator.add(this, aComputersFragment); } @Override diff --git a/android/sdremote/src/org/libreoffice/impressremote/activity/SettingsActivity.java b/android/sdremote/src/org/libreoffice/impressremote/activity/SettingsActivity.java index ea1a9a5bc208..00ae39033eb4 100644 --- a/android/sdremote/src/org/libreoffice/impressremote/activity/SettingsActivity.java +++ b/android/sdremote/src/org/libreoffice/impressremote/activity/SettingsActivity.java @@ -32,6 +32,8 @@ public class SettingsActivity extends SherlockPreferenceActivity { // This action is deprecated // but we still need to target pre-Honeycomb devices. + // TODO: try to use a fragment depending on platform version + addPreferencesFromResource(R.xml.preferences); } diff --git a/android/sdremote/src/org/libreoffice/impressremote/activity/SlideShowActivity.java b/android/sdremote/src/org/libreoffice/impressremote/activity/SlideShowActivity.java index 76ae2e710398..45fe40add314 100644 --- a/android/sdremote/src/org/libreoffice/impressremote/activity/SlideShowActivity.java +++ b/android/sdremote/src/org/libreoffice/impressremote/activity/SlideShowActivity.java @@ -34,7 +34,7 @@ import org.libreoffice.impressremote.fragment.SlidesGridFragment; import org.libreoffice.impressremote.fragment.SlidesPagerFragment; import org.libreoffice.impressremote.fragment.TimerEditingDialog; import org.libreoffice.impressremote.fragment.TimerSettingDialog; -import org.libreoffice.impressremote.util.FragmentOperator; +import org.libreoffice.impressremote.util.Fragments; import org.libreoffice.impressremote.util.Intents; import org.libreoffice.impressremote.util.Preferences; import org.libreoffice.impressremote.util.SavedStates; @@ -75,7 +75,7 @@ public class SlideShowActivity extends SherlockFragmentActivity implements Servi } private void setUpFragment() { - FragmentOperator.replaceFragmentAnimated(this, buildFragment()); + Fragments.Operator.replaceAnimated(this, buildFragment()); } private Fragment buildFragment() { @@ -123,7 +123,7 @@ public class SlideShowActivity extends SherlockFragmentActivity implements Servi return; } - mCommunicationService.getTransmitter().startPresentation(); + mCommunicationService.getCommandsTransmitter().startPresentation(); } @Override @@ -268,12 +268,12 @@ public class SlideShowActivity extends SherlockFragmentActivity implements Servi switch (aKeyCode) { case KeyEvent.KEYCODE_VOLUME_UP: if (!isLastSlideDisplayed()) { - mCommunicationService.getTransmitter().performNextTransition(); + mCommunicationService.getCommandsTransmitter().performNextTransition(); } return true; case KeyEvent.KEYCODE_VOLUME_DOWN: - mCommunicationService.getTransmitter().performPreviousTransition(); + mCommunicationService.getCommandsTransmitter().performPreviousTransition(); return true; default: @@ -446,11 +446,11 @@ public class SlideShowActivity extends SherlockFragmentActivity implements Servi } private void resumeSlideShow() { - mCommunicationService.getTransmitter().resumePresentation(); + mCommunicationService.getCommandsTransmitter().resumePresentation(); } private void pauseSlideShow() { - mCommunicationService.getTransmitter().setUpBlankScreen(); + mCommunicationService.getCommandsTransmitter().setUpBlankScreen(); } private void setUpSlideShowPausedInformation() { @@ -465,7 +465,7 @@ public class SlideShowActivity extends SherlockFragmentActivity implements Servi } private void stopSlideShow() { - mCommunicationService.getTransmitter().stopPresentation(); + mCommunicationService.getCommandsTransmitter().stopPresentation(); finish(); } diff --git a/android/sdremote/src/org/libreoffice/impressremote/communication/BluetoothServersFinder.java b/android/sdremote/src/org/libreoffice/impressremote/communication/BluetoothServersFinder.java index 2dbb6e6f713a..4d7619b49e30 100644 --- a/android/sdremote/src/org/libreoffice/impressremote/communication/BluetoothServersFinder.java +++ b/android/sdremote/src/org/libreoffice/impressremote/communication/BluetoothServersFinder.java @@ -102,8 +102,8 @@ class BluetoothServersFinder extends BroadcastReceiver implements ServersFinder, return; } - Handler aHandler = new Handler(); - aHandler.postDelayed(this, TimeUnit.SECONDS.toMillis(SEARCH_DELAY_IN_SECONDS)); + Handler aDiscoveryHandler = new Handler(); + aDiscoveryHandler.postDelayed(this, TimeUnit.SECONDS.toMillis(SEARCH_DELAY_IN_SECONDS)); } @Override diff --git a/android/sdremote/src/org/libreoffice/impressremote/communication/CommunicationService.java b/android/sdremote/src/org/libreoffice/impressremote/communication/CommunicationService.java index ed2e5c23c671..cbeacd6bfe5f 100644 --- a/android/sdremote/src/org/libreoffice/impressremote/communication/CommunicationService.java +++ b/android/sdremote/src/org/libreoffice/impressremote/communication/CommunicationService.java @@ -111,6 +111,18 @@ public class CommunicationService extends Service implements Runnable, MessagesL } } + public void disconnectServer() { + if (!isServerConnectionAvailable()) { + return; + } + + mServerConnection.close(); + } + + private boolean isServerConnectionAvailable() { + return mServerConnection != null; + } + private void connectServer() { mServerConnection = buildServerConnection(); mServerConnection.open(); @@ -148,19 +160,7 @@ public class CommunicationService extends Service implements Runnable, MessagesL LocalBroadcastManager.getInstance(this).sendBroadcast(aIntent); } - public void disconnectServer() { - if (!isServerConnectionAvailable()) { - return; - } - - mServerConnection.close(); - } - - private boolean isServerConnectionAvailable() { - return mServerConnection != null; - } - - public CommandsTransmitter getTransmitter() { + public CommandsTransmitter getCommandsTransmitter() { return mCommandsTransmitter; } diff --git a/android/sdremote/src/org/libreoffice/impressremote/communication/PairingProvider.java b/android/sdremote/src/org/libreoffice/impressremote/communication/PairingProvider.java index f91fbf7163e9..f5f4fe4f88fb 100644 --- a/android/sdremote/src/org/libreoffice/impressremote/communication/PairingProvider.java +++ b/android/sdremote/src/org/libreoffice/impressremote/communication/PairingProvider.java @@ -8,10 +8,10 @@ */ package org.libreoffice.impressremote.communication; -import android.bluetooth.BluetoothAdapter; import android.content.Context; import android.os.Build; +import org.libreoffice.impressremote.util.BluetoothOperator; import org.libreoffice.impressremote.util.Preferences; final class PairingProvider { @@ -58,15 +58,15 @@ final class PairingProvider { } private String getPairingDeviceName() { - if (BluetoothAdapter.getDefaultAdapter() == null) { + if (!BluetoothOperator.isAvailable()) { return Build.MODEL; } - if (BluetoothAdapter.getDefaultAdapter().getName() == null) { + if (BluetoothOperator.getAdapter().getName() == null) { return Build.MODEL; } - return BluetoothAdapter.getDefaultAdapter().getName(); + return BluetoothOperator.getAdapter().getName(); } } diff --git a/android/sdremote/src/org/libreoffice/impressremote/fragment/SlidesGridFragment.java b/android/sdremote/src/org/libreoffice/impressremote/fragment/SlidesGridFragment.java index 1d32ed30430e..14e46e0a1dac 100644 --- a/android/sdremote/src/org/libreoffice/impressremote/fragment/SlidesGridFragment.java +++ b/android/sdremote/src/org/libreoffice/impressremote/fragment/SlidesGridFragment.java @@ -86,7 +86,7 @@ public class SlidesGridFragment extends SherlockFragment implements ServiceConne @Override public void onItemClick(AdapterView<?> aAdapterView, View aView, int aPosition, long aId) { - mCommunicationService.getTransmitter().setCurrentSlide(aPosition); + mCommunicationService.getCommandsTransmitter().setCurrentSlide(aPosition); } @Override diff --git a/android/sdremote/src/org/libreoffice/impressremote/fragment/SlidesPagerFragment.java b/android/sdremote/src/org/libreoffice/impressremote/fragment/SlidesPagerFragment.java index 346c79e26376..aba2e21055ef 100644 --- a/android/sdremote/src/org/libreoffice/impressremote/fragment/SlidesPagerFragment.java +++ b/android/sdremote/src/org/libreoffice/impressremote/fragment/SlidesPagerFragment.java @@ -111,7 +111,7 @@ public class SlidesPagerFragment extends SherlockFragment implements ServiceConn } private void showNextTransition() { - mCommunicationService.getTransmitter().performNextTransition(); + mCommunicationService.getCommandsTransmitter().performNextTransition(); } private int getSlidesMargin() { @@ -133,7 +133,7 @@ public class SlidesPagerFragment extends SherlockFragment implements ServiceConn @Override public void onPageSelected(int aPosition) { if (mCommunicationService.getSlideShow().getCurrentSlideIndex() != aPosition) { - mCommunicationService.getTransmitter().setCurrentSlide(aPosition); + mCommunicationService.getCommandsTransmitter().setCurrentSlide(aPosition); } setUpSlideNotes(aPosition); diff --git a/android/sdremote/src/org/libreoffice/impressremote/util/FragmentOperator.java b/android/sdremote/src/org/libreoffice/impressremote/util/FragmentOperator.java deleted file mode 100644 index af7e47c5b700..000000000000 --- a/android/sdremote/src/org/libreoffice/impressremote/util/FragmentOperator.java +++ /dev/null @@ -1,54 +0,0 @@ -/* -*- Mode: Java; tab-width: 4; indent-tabs-mode: nil; c-basic-offset: 4 -*- */ -/* - * This file is part of the LibreOffice project. - * - * This Source Code Form is subject to the terms of the Mozilla Public - * License, v. 2.0. If a copy of the MPL was not distributed with this - * file, You can obtain one at http://mozilla.org/MPL/2.0/. - */ -package org.libreoffice.impressremote.util; - -import android.support.v4.app.Fragment; -import android.support.v4.app.FragmentActivity; -import android.support.v4.app.FragmentManager; -import android.support.v4.app.FragmentTransaction; - -public final class FragmentOperator { - private FragmentOperator() { - } - - public static void addFragment(FragmentActivity aActivity, Fragment aFragment) { - if (isFragmentAdded(aActivity)) { - return; - } - - FragmentTransaction aFragmentTransaction = beginFragmentTransaction(aActivity); - - aFragmentTransaction.add(android.R.id.content, aFragment); - - aFragmentTransaction.commit(); - } - - private static boolean isFragmentAdded(FragmentActivity aActivity) { - FragmentManager aFragmentManager = aActivity.getSupportFragmentManager(); - - return aFragmentManager.findFragmentById(android.R.id.content) != null; - } - - private static FragmentTransaction beginFragmentTransaction(FragmentActivity aActivity) { - FragmentManager aFragmentManager = aActivity.getSupportFragmentManager(); - - return aFragmentManager.beginTransaction(); - } - - public static void replaceFragmentAnimated(FragmentActivity aActivity, Fragment aFragment) { - FragmentTransaction aFragmentTransaction = beginFragmentTransaction(aActivity); - aFragmentTransaction.setCustomAnimations(android.R.anim.fade_in, android.R.anim.fade_out); - - aFragmentTransaction.replace(android.R.id.content, aFragment); - - aFragmentTransaction.commit(); - } -} - -/* vim:set shiftwidth=4 softtabstop=4 expandtab: */ diff --git a/android/sdremote/src/org/libreoffice/impressremote/util/Fragments.java b/android/sdremote/src/org/libreoffice/impressremote/util/Fragments.java index 3b180580052e..fae8819ad8da 100644 --- a/android/sdremote/src/org/libreoffice/impressremote/util/Fragments.java +++ b/android/sdremote/src/org/libreoffice/impressremote/util/Fragments.java @@ -8,6 +8,11 @@ */ package org.libreoffice.impressremote.util; +import android.support.v4.app.Fragment; +import android.support.v4.app.FragmentActivity; +import android.support.v4.app.FragmentManager; +import android.support.v4.app.FragmentTransaction; + public final class Fragments { private Fragments() { } @@ -20,6 +25,44 @@ public final class Fragments { public static final String MINUTES = "MINUTES"; public static final String TYPE = "TYPE"; } + + public static final class Operator { + private Operator() { + } + + public static void add(FragmentActivity aActivity, Fragment aFragment) { + if (isAdded(aActivity)) { + return; + } + + FragmentTransaction aFragmentTransaction = beginTransaction(aActivity); + + aFragmentTransaction.add(android.R.id.content, aFragment); + + aFragmentTransaction.commit(); + } + + private static boolean isAdded(FragmentActivity aActivity) { + FragmentManager aFragmentManager = aActivity.getSupportFragmentManager(); + + return aFragmentManager.findFragmentById(android.R.id.content) != null; + } + + private static FragmentTransaction beginTransaction(FragmentActivity aActivity) { + FragmentManager aFragmentManager = aActivity.getSupportFragmentManager(); + + return aFragmentManager.beginTransaction(); + } + + public static void replaceAnimated(FragmentActivity aActivity, Fragment aFragment) { + FragmentTransaction aFragmentTransaction = beginTransaction(aActivity); + aFragmentTransaction.setCustomAnimations(android.R.anim.fade_in, android.R.anim.fade_out); + + aFragmentTransaction.replace(android.R.id.content, aFragment); + + aFragmentTransaction.commit(); + } + } } /* vim:set shiftwidth=4 softtabstop=4 expandtab: */ diff --git a/android/sdremote/src/org/libreoffice/impressremote/util/Intents.java b/android/sdremote/src/org/libreoffice/impressremote/util/Intents.java index 20c56fb7073f..a6ade2dc70cd 100644 --- a/android/sdremote/src/org/libreoffice/impressremote/util/Intents.java +++ b/android/sdremote/src/org/libreoffice/impressremote/util/Intents.java @@ -52,15 +52,13 @@ public final class Intents { private Extras() { } + public static final String MINUTES = "MINUTES"; public static final String PIN = "PIN"; + public static final String SLIDE_INDEX = "SLIDE_INDEX"; public static final String SERVER = "SERVER"; public static final String SERVER_ADDRESS = "SERVER_ADDRESS"; public static final String SERVER_NAME = "SERVER_NAME"; - - public static final String SLIDE_INDEX = "SLIDE_INDEX"; - - public static final String MINUTES = "MINUTES"; } public static final class RequestCodes { diff --git a/android/sdremote/src/org/libreoffice/impressremote/util/Preferences.java b/android/sdremote/src/org/libreoffice/impressremote/util/Preferences.java index 0a2141b385ad..5a9b0c783288 100644 --- a/android/sdremote/src/org/libreoffice/impressremote/util/Preferences.java +++ b/android/sdremote/src/org/libreoffice/impressremote/util/Preferences.java @@ -45,16 +45,20 @@ public final class Preferences { private final SharedPreferences mPreferences; - public static Preferences getAuthorizedServersInstance(Context aContext) { - return new Preferences(aContext, Locations.AUTHORIZED_SERVERS); + private Preferences(Context context) { + mPreferences = PreferenceManager.getDefaultSharedPreferences(context); } private Preferences(Context aContext, String aLocation) { - mPreferences = getPreferences(aContext, aLocation); + mPreferences = aContext.getSharedPreferences(aLocation, Context.MODE_PRIVATE); } - private SharedPreferences getPreferences(Context aContext, String aLocation) { - return aContext.getSharedPreferences(aLocation, Context.MODE_PRIVATE); + public static Preferences getSettingsInstance(Context context) { + return new Preferences(context); + } + + public static Preferences getAuthorizedServersInstance(Context aContext) { + return new Preferences(aContext, Locations.AUTHORIZED_SERVERS); } public static Preferences getSavedServersInstance(Context aContext) { @@ -65,14 +69,6 @@ public final class Preferences { return new Preferences(aContext, Locations.APPLICATION_STATES); } - public static Preferences getSettingsInstance(Context context) { - return new Preferences(context); - } - - private Preferences(Context context) { - mPreferences = PreferenceManager.getDefaultSharedPreferences(context); - } - public Map<String, ?> getAll() { return mPreferences.getAll(); } diff --git a/android/sdremote/src/org/libreoffice/impressremote/util/SavedStates.java b/android/sdremote/src/org/libreoffice/impressremote/util/SavedStates.java index 0ec6b56c5f19..e3e37b2d5250 100644 --- a/android/sdremote/src/org/libreoffice/impressremote/util/SavedStates.java +++ b/android/sdremote/src/org/libreoffice/impressremote/util/SavedStates.java @@ -1,3 +1,11 @@ +/* -*- Mode: Java; tab-width: 4; indent-tabs-mode: nil; c-basic-offset: 4 -*- */ +/* + * This file is part of the LibreOffice project. + * + * This Source Code Form is subject to the terms of the Mozilla Public + * License, v. 2.0. If a copy of the MPL was not distributed with this + * file, You can obtain one at http://mozilla.org/MPL/2.0/. + */ package org.libreoffice.impressremote.util; public final class SavedStates { @@ -8,13 +16,12 @@ public final class SavedStates { private Keys() { } - public static final String PROGRESS_MESSAGE = "PROGRESS_MESSAGE"; - - public static final String LAYOUT_INDEX = "LAYOUT_INDEX"; - - public static final String PIN = "PIN"; public static final String ERROR_MESSAGE = "ERROR_MESSAGE"; - + public static final String LAYOUT_INDEX = "LAYOUT_INDEX"; public static final String MODE = "MODE"; + public static final String PIN = "PIN"; + public static final String PROGRESS_MESSAGE = "PROGRESS_MESSAGE"; } } + +/* vim:set shiftwidth=4 softtabstop=4 expandtab: */ |