mirror of
https://codeberg.org/OpenTracksApp/OpenTracks.git
synced 2026-10-11 05:23:07 +02:00
Remove api level 7 code.
This commit is contained in:
@@ -119,9 +119,4 @@ public class Api11Adapter extends Api10Adapter {
|
||||
public void invalidMenu(Activity activity) {
|
||||
activity.invalidateOptionsMenu();
|
||||
}
|
||||
|
||||
@Override
|
||||
public void disableHardwareAccelerated(View view) {
|
||||
view.setLayerType(View.LAYER_TYPE_SOFTWARE, null);
|
||||
}
|
||||
}
|
||||
|
||||
@@ -1,165 +0,0 @@
|
||||
/*
|
||||
* Copyright 2010 Google Inc.
|
||||
*
|
||||
* Licensed under the Apache License, Version 2.0 (the "License"); you may not
|
||||
* use this file except in compliance with the License. You may obtain a copy of
|
||||
* the License at
|
||||
*
|
||||
* http://www.apache.org/licenses/LICENSE-2.0
|
||||
*
|
||||
* Unless required by applicable law or agreed to in writing, software
|
||||
* distributed under the License is distributed on an "AS IS" BASIS, WITHOUT
|
||||
* WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. See the
|
||||
* License for the specific language governing permissions and limitations under
|
||||
* the License.
|
||||
*/
|
||||
package com.google.android.apps.mytracks.util;
|
||||
|
||||
import com.google.android.apps.mytracks.Constants;
|
||||
import com.google.android.apps.mytracks.ContextualActionModeCallback;
|
||||
import com.google.android.apps.mytracks.io.backup.BackupPreferencesListener;
|
||||
import com.google.android.apps.mytracks.services.sensors.BluetoothConnectionManager;
|
||||
import com.google.android.apps.mytracks.services.tasks.AnnouncementPeriodicTask;
|
||||
import com.google.android.apps.mytracks.services.tasks.PeriodicTask;
|
||||
import com.google.api.client.http.HttpTransport;
|
||||
import com.google.api.client.http.apache.ApacheHttpTransport;
|
||||
|
||||
import android.app.Activity;
|
||||
import android.bluetooth.BluetoothDevice;
|
||||
import android.bluetooth.BluetoothSocket;
|
||||
import android.content.Context;
|
||||
import android.content.SharedPreferences;
|
||||
import android.content.SharedPreferences.Editor;
|
||||
import android.util.Log;
|
||||
import android.view.MenuItem;
|
||||
import android.view.View;
|
||||
import android.view.Window;
|
||||
import android.widget.ArrayAdapter;
|
||||
import android.widget.ListView;
|
||||
|
||||
import java.io.IOException;
|
||||
import java.lang.reflect.InvocationTargetException;
|
||||
import java.lang.reflect.Method;
|
||||
import java.util.List;
|
||||
|
||||
/**
|
||||
* API level 7 specific implementation of the {@link ApiAdapter}.
|
||||
*
|
||||
* @author Bartlomiej Niechwiej
|
||||
*/
|
||||
public class Api7Adapter implements ApiAdapter {
|
||||
|
||||
@Override
|
||||
public PeriodicTask getAnnouncementPeriodicTask(Context context) {
|
||||
return new AnnouncementPeriodicTask(context);
|
||||
}
|
||||
|
||||
@Override
|
||||
public BackupPreferencesListener getBackupPreferencesListener(Context context) {
|
||||
return new BackupPreferencesListener() {
|
||||
@Override
|
||||
public void onSharedPreferenceChanged(SharedPreferences sharedPreferences, String key) {
|
||||
// Do nothing
|
||||
}
|
||||
};
|
||||
}
|
||||
|
||||
@Override
|
||||
public void applyPreferenceChanges(Editor editor) {
|
||||
editor.commit();
|
||||
}
|
||||
|
||||
@Override
|
||||
public void enableStrictMode() {
|
||||
// Not supported
|
||||
}
|
||||
|
||||
@Override
|
||||
public byte[] copyByteArray(byte[] input, int start, int end) {
|
||||
int length = end - start;
|
||||
byte[] output = new byte[length];
|
||||
System.arraycopy(input, start, output, 0, length);
|
||||
return output;
|
||||
}
|
||||
|
||||
@Override
|
||||
public HttpTransport getHttpTransport() {
|
||||
return new ApacheHttpTransport();
|
||||
}
|
||||
|
||||
@Override
|
||||
public boolean isGeoCoderPresent() {
|
||||
return true;
|
||||
}
|
||||
|
||||
@Override
|
||||
public BluetoothSocket getBluetoothSocket(BluetoothDevice bluetoothDevice) throws IOException {
|
||||
try {
|
||||
Class<? extends BluetoothDevice> c = bluetoothDevice.getClass();
|
||||
Method insecure = c.getMethod("createInsecureRfcommSocket", Integer.class);
|
||||
insecure.setAccessible(true);
|
||||
return (BluetoothSocket) insecure.invoke(bluetoothDevice, 1);
|
||||
} catch (SecurityException e) {
|
||||
Log.d(Constants.TAG, "Unable to create insecure connection", e);
|
||||
} catch (NoSuchMethodException e) {
|
||||
Log.d(Constants.TAG, "Unable to create insecure connection", e);
|
||||
} catch (IllegalArgumentException e) {
|
||||
Log.d(Constants.TAG, "Unable to create insecure connection", e);
|
||||
} catch (IllegalAccessException e) {
|
||||
Log.d(Constants.TAG, "Unable to create insecure connection", e);
|
||||
} catch (InvocationTargetException e) {
|
||||
Log.d(Constants.TAG, "Unable to create insecure connection", e);
|
||||
}
|
||||
return bluetoothDevice.createRfcommSocketToServiceRecord(BluetoothConnectionManager.MY_TRACKS_UUID);
|
||||
}
|
||||
|
||||
@Override
|
||||
public void hideTitle(Activity activity) {
|
||||
activity.requestWindowFeature(Window.FEATURE_NO_TITLE);
|
||||
}
|
||||
|
||||
@Override
|
||||
public void configureActionBarHomeAsUp(Activity activity) {
|
||||
// Do nothing
|
||||
}
|
||||
|
||||
@Override
|
||||
public void configureListViewContextualMenu(Activity activity, ListView listView,
|
||||
ContextualActionModeCallback contextualActionModeCallback) {
|
||||
activity.registerForContextMenu(listView);
|
||||
}
|
||||
|
||||
@Override
|
||||
public void configureSearchWidget(Activity activity, MenuItem menuItem) {
|
||||
// Do nothing
|
||||
}
|
||||
|
||||
@Override
|
||||
public boolean handleSearchMenuSelection(Activity activity) {
|
||||
activity.onSearchRequested();
|
||||
return true;
|
||||
}
|
||||
|
||||
@Override
|
||||
public <T> void addAllToArrayAdapter(ArrayAdapter<T> arrayAdapter, List<T> items) {
|
||||
for (T item : items) {
|
||||
arrayAdapter.add(item);
|
||||
}
|
||||
}
|
||||
|
||||
@Override
|
||||
public void invalidMenu(Activity activity) {
|
||||
// Do nothing
|
||||
}
|
||||
|
||||
@Override
|
||||
public void disableHardwareAccelerated(View view) {
|
||||
// Do nothing
|
||||
}
|
||||
|
||||
@Override
|
||||
public boolean handleSearchKey(MenuItem menuItem) {
|
||||
// Return false and allow the framework to handle the search key.
|
||||
return false;
|
||||
}
|
||||
}
|
||||
@@ -1,5 +1,5 @@
|
||||
/*
|
||||
* Copyright 2012 Google Inc.
|
||||
* Copyright 2010 Google Inc.
|
||||
*
|
||||
* Licensed under the Apache License, Version 2.0 (the "License"); you may not
|
||||
* use this file except in compliance with the License. You may obtain a copy of
|
||||
@@ -15,27 +15,125 @@
|
||||
*/
|
||||
package com.google.android.apps.mytracks.util;
|
||||
|
||||
import com.google.android.apps.mytracks.io.backup.Api8BackupPreferencesListener;
|
||||
import com.google.android.apps.mytracks.io.backup.BackupPreferencesListener;
|
||||
import com.google.android.apps.mytracks.services.tasks.Api8AnnouncementPeriodicTask;
|
||||
import com.google.android.apps.mytracks.services.tasks.PeriodicTask;
|
||||
import com.google.android.apps.mytracks.Constants;
|
||||
import com.google.android.apps.mytracks.ContextualActionModeCallback;
|
||||
import com.google.android.apps.mytracks.services.sensors.BluetoothConnectionManager;
|
||||
import com.google.api.client.http.HttpTransport;
|
||||
import com.google.api.client.http.apache.ApacheHttpTransport;
|
||||
|
||||
import android.content.Context;
|
||||
import android.app.Activity;
|
||||
import android.bluetooth.BluetoothDevice;
|
||||
import android.bluetooth.BluetoothSocket;
|
||||
import android.content.SharedPreferences.Editor;
|
||||
import android.util.Log;
|
||||
import android.view.MenuItem;
|
||||
import android.view.Window;
|
||||
import android.widget.ArrayAdapter;
|
||||
import android.widget.ListView;
|
||||
|
||||
import java.io.IOException;
|
||||
import java.lang.reflect.InvocationTargetException;
|
||||
import java.lang.reflect.Method;
|
||||
import java.util.List;
|
||||
|
||||
/**
|
||||
* API level 8 specific implementation of the {@link ApiAdapter}.
|
||||
*
|
||||
* @author Jimmy Shih
|
||||
* @author Bartlomiej Niechwiej
|
||||
*/
|
||||
public class Api8Adapter extends Api7Adapter {
|
||||
|
||||
public class Api8Adapter implements ApiAdapter {
|
||||
|
||||
@Override
|
||||
public PeriodicTask getAnnouncementPeriodicTask(Context context) {
|
||||
return new Api8AnnouncementPeriodicTask(context);
|
||||
public void applyPreferenceChanges(Editor editor) {
|
||||
editor.commit();
|
||||
}
|
||||
|
||||
|
||||
@Override
|
||||
public BackupPreferencesListener getBackupPreferencesListener(Context context) {
|
||||
return new Api8BackupPreferencesListener(context);
|
||||
public void enableStrictMode() {
|
||||
// Not supported
|
||||
}
|
||||
|
||||
@Override
|
||||
public byte[] copyByteArray(byte[] input, int start, int end) {
|
||||
int length = end - start;
|
||||
byte[] output = new byte[length];
|
||||
System.arraycopy(input, start, output, 0, length);
|
||||
return output;
|
||||
}
|
||||
|
||||
@Override
|
||||
public HttpTransport getHttpTransport() {
|
||||
return new ApacheHttpTransport();
|
||||
}
|
||||
|
||||
@Override
|
||||
public boolean isGeoCoderPresent() {
|
||||
return true;
|
||||
}
|
||||
|
||||
@Override
|
||||
public BluetoothSocket getBluetoothSocket(BluetoothDevice bluetoothDevice) throws IOException {
|
||||
try {
|
||||
Class<? extends BluetoothDevice> c = bluetoothDevice.getClass();
|
||||
Method insecure = c.getMethod("createInsecureRfcommSocket", Integer.class);
|
||||
insecure.setAccessible(true);
|
||||
return (BluetoothSocket) insecure.invoke(bluetoothDevice, 1);
|
||||
} catch (SecurityException e) {
|
||||
Log.d(Constants.TAG, "Unable to create insecure connection", e);
|
||||
} catch (NoSuchMethodException e) {
|
||||
Log.d(Constants.TAG, "Unable to create insecure connection", e);
|
||||
} catch (IllegalArgumentException e) {
|
||||
Log.d(Constants.TAG, "Unable to create insecure connection", e);
|
||||
} catch (IllegalAccessException e) {
|
||||
Log.d(Constants.TAG, "Unable to create insecure connection", e);
|
||||
} catch (InvocationTargetException e) {
|
||||
Log.d(Constants.TAG, "Unable to create insecure connection", e);
|
||||
}
|
||||
return bluetoothDevice.createRfcommSocketToServiceRecord(BluetoothConnectionManager.MY_TRACKS_UUID);
|
||||
}
|
||||
|
||||
@Override
|
||||
public void hideTitle(Activity activity) {
|
||||
activity.requestWindowFeature(Window.FEATURE_NO_TITLE);
|
||||
}
|
||||
|
||||
@Override
|
||||
public void configureActionBarHomeAsUp(Activity activity) {
|
||||
// Do nothing
|
||||
}
|
||||
|
||||
@Override
|
||||
public void configureListViewContextualMenu(Activity activity, ListView listView,
|
||||
ContextualActionModeCallback contextualActionModeCallback) {
|
||||
activity.registerForContextMenu(listView);
|
||||
}
|
||||
|
||||
@Override
|
||||
public void configureSearchWidget(Activity activity, MenuItem menuItem) {
|
||||
// Do nothing
|
||||
}
|
||||
|
||||
@Override
|
||||
public boolean handleSearchMenuSelection(Activity activity) {
|
||||
activity.onSearchRequested();
|
||||
return true;
|
||||
}
|
||||
|
||||
@Override
|
||||
public <T> void addAllToArrayAdapter(ArrayAdapter<T> arrayAdapter, List<T> items) {
|
||||
for (T item : items) {
|
||||
arrayAdapter.add(item);
|
||||
}
|
||||
}
|
||||
|
||||
@Override
|
||||
public void invalidMenu(Activity activity) {
|
||||
// Do nothing
|
||||
}
|
||||
|
||||
@Override
|
||||
public boolean handleSearchKey(MenuItem menuItem) {
|
||||
// Return false and allow the framework to handle the search key.
|
||||
return false;
|
||||
}
|
||||
}
|
||||
|
||||
@@ -16,17 +16,13 @@
|
||||
package com.google.android.apps.mytracks.util;
|
||||
|
||||
import com.google.android.apps.mytracks.ContextualActionModeCallback;
|
||||
import com.google.android.apps.mytracks.io.backup.BackupPreferencesListener;
|
||||
import com.google.android.apps.mytracks.services.tasks.PeriodicTask;
|
||||
import com.google.api.client.http.HttpTransport;
|
||||
|
||||
import android.app.Activity;
|
||||
import android.bluetooth.BluetoothDevice;
|
||||
import android.bluetooth.BluetoothSocket;
|
||||
import android.content.Context;
|
||||
import android.content.SharedPreferences;
|
||||
import android.view.MenuItem;
|
||||
import android.view.View;
|
||||
import android.widget.ArrayAdapter;
|
||||
import android.widget.ListView;
|
||||
|
||||
@@ -41,24 +37,6 @@ import java.util.List;
|
||||
*/
|
||||
public interface ApiAdapter {
|
||||
|
||||
/**
|
||||
* Gets an announcement periodic task.
|
||||
* <p>
|
||||
* Due to changes in API level 8.
|
||||
*
|
||||
* @param context the context
|
||||
*/
|
||||
public PeriodicTask getAnnouncementPeriodicTask(Context context);
|
||||
|
||||
/**
|
||||
* Gets a {@link BackupPreferencesListener}.
|
||||
* <p>
|
||||
* Due to changes in API level 8.
|
||||
*
|
||||
* @param context the context
|
||||
*/
|
||||
public BackupPreferencesListener getBackupPreferencesListener(Context context);
|
||||
|
||||
/**
|
||||
* Applies all the changes done to a given preferences editor. Changes may or
|
||||
* may not be applied immediately.
|
||||
@@ -184,15 +162,6 @@ public interface ApiAdapter {
|
||||
*/
|
||||
public void invalidMenu(Activity activity);
|
||||
|
||||
/**
|
||||
* Diables hardware-accelerated rendering for a view.
|
||||
* <p>
|
||||
* Due to chagnes in API level 11.
|
||||
*
|
||||
* @param view the view
|
||||
*/
|
||||
public void disableHardwareAccelerated(View view);
|
||||
|
||||
/**
|
||||
* Handles the search key press. Returns true if handled.
|
||||
* <p>
|
||||
|
||||
@@ -43,11 +43,8 @@ public class ApiAdapterFactory {
|
||||
} else if (Build.VERSION.SDK_INT >= 9) {
|
||||
apiAdapter = new Api9Adapter();
|
||||
return apiAdapter;
|
||||
} else if (Build.VERSION.SDK_INT >= 8) {
|
||||
apiAdapter = new Api8Adapter();
|
||||
return apiAdapter;
|
||||
} else {
|
||||
apiAdapter = new Api7Adapter();
|
||||
apiAdapter = new Api8Adapter();
|
||||
return apiAdapter;
|
||||
}
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user