Fix another code style issues.

Change-Id: Id76d17050b7fc2865a78b9a815a2f543e85e321f
This commit is contained in:
Artur Dryomov 2013-09-14 15:02:47 +03:00
parent fff70bf98c
commit 2436d8c9bc
15 changed files with 114 additions and 116 deletions

View File

@ -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

View File

@ -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);

View File

@ -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

View File

@ -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);
}

View File

@ -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();
}

View File

@ -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

View File

@ -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;
}

View File

@ -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();
}
}

View File

@ -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

View File

@ -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);

View File

@ -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: */

View File

@ -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: */

View File

@ -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 {

View File

@ -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();
}

View File

@ -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: */