I am using VideoView to play live streams and it works fine most of the time, but sometimes the app freezes for a moment and either continues to play or crash and send me to home screen.
This is what happens when i select an item from the listview or click KEY_DOWN / KEY_UP:
public boolean onKeyDown(int keyCode, KeyEvent event) {
if (keyCode == KeyEvent.KEYCODE_DPAD_DOWN) {
if (mVideoView != null && mListView == null) {
if (listViewNext != listViewCurrent) { playChannel(listViewNext, 0); }
return true;
}
}
}
private void playChannel(int channel, int id) {
listViewCurrent = channel;
listViewNext = listViewCurrent + 1;
listViewPrev = listViewCurrent - 1;
if (mListViewChannels == "Danish") {
if (listViewNext >= arrayDanishChannels.size()) { listViewNext = 0; }
if (listViewPrev < 0) { listViewPrev = arrayDanishChannels.size() - 1; }
mListViewLink = arrayDanishLinks.get(listViewCurrent);
} else if (mListViewChannels == "World") {
if (listViewNext >= arrayWorldChannels.size()) { listViewNext = 0; }
if (listViewPrev < 0) { listViewPrev = arrayWorldChannels.size() - 1; }
mListViewLink = arrayWorldLinks.get(listViewCurrent);
}
String listViewName = (String) listView.getItemAtPosition(listViewCurrent);
String[] links = mListViewLink.split(";"); int temp = id + 1;
if (id < 0 || temp > links.length) { id = 0; temp = 1; }
mListViewLink = links[id]; listViewLinkId = temp; listViewLinkIds = links.length;
startVideo(listViewName+" ("+listViewLinkId+"/"+listViewLinkIds+")", mListViewLink);
mListViewCurrent = mListViewChannels;
}
private void startVideo(String title, String link) {
toastDisplay.cancel();
setInfoView(title);
imageView.setVisibility(ImageView.INVISIBLE);
videoView.removeCallbacks(videoRunnable);
videoView.stopPlayback();
MediaController media = new MediaController(MainActivity.this); media.setAnchorView(videoView); media.setMediaPlayer(videoView);
videoView.setMediaController(media);
videoView.setVideoPath(link);
videoView.setOnPreparedListener(videoViewPreparedListener);
videoView.setOnErrorListener(videoViewErrorListener);
videoView.setVisibility(VideoView.VISIBLE);
videoView.postDelayed(videoRunnable, videoViewTimeOut);
videoView.start();
mVideoView = "true";
SharedPreferences pref = PreferenceManager.getDefaultSharedPreferences(MainActivity.this);
SharedPreferences.Editor edit = pref.edit();
edit.putString("setLastStream", title+";"+mListViewChannels);
edit.apply();
}
private void setInfoView(String title) {
infoView.removeCallbacks(infoRunnable);
infoView.setText(title);
infoView.setVisibility(TextView.VISIBLE);
progressBar.setVisibility(ProgressBar.VISIBLE);
}
Just a note: I have payed for the streams and some are free to access for anyone, no illegal content.
I am using an android set top box with firmware 4.4.2
I have tried to add try { .. } finally { .. } everywhere and it still freezes sometimes at random times.
Please help, im new in making apps and this is really driving me crazy.
Sorry for my bad english.
Related
I have ExoPlayer which plays HLS videos, the thing is i need to give user ability to change video quality(auto/1080/720/480).
I figured out that playing around with AdaptiveTrackSelection.Factory does set the quality, but it remains till the object is killed.
I have also tried using MappingTrackSelector, i know that my video has 4 tracks, but i did not get how to select any of it manually. Will this selection make it work?
Thanks for any ideas.
MappingTrackSelector.MappedTrackInfo trackInfo = mDefaultTrackSelector.getCurrentMappedTrackInfo();
mDefaultTrackSelector.selectTracks(
//what should go here?
, trackInfo.getTrackGroups(4));
Regarding this thread :https://github.com/google/ExoPlayer/issues/2250, I managed to change exo player video quality while playing previous one, so it does not getting in buffering instantly.
So I have next classes :
public enum HLSQuality {
Auto, Quality1080, Quality720, Quality480, NoValue
}
class HLSUtil {
private HLSUtil() {
}
#NonNull
static HLSQuality getQuality(#NonNull Format format) {
switch (format.height) {
case 1080: {
return HLSQuality.Quality1080;
}
case 720: {
return HLSQuality.Quality720;
}
case 480:
case 486: {
return HLSQuality.Quality480;
}
default: {
return HLSQuality.NoValue;
}
}
}
static boolean isQualityPlayable(#NonNull Format format) {
return format.height <= 1080;
}
}
public class ClassAdaptiveTrackSelection extends BaseTrackSelection {
public static final class Factory implements TrackSelection.Factory {
private final BandwidthMeter bandwidthMeter;
private final int maxInitialBitrate = 2000000;
private final int minDurationForQualityIncreaseMs = 10000;
private final int maxDurationForQualityDecreaseMs = 25000;
private final int minDurationToRetainAfterDiscardMs = 25000;
private final float bandwidthFraction = 0.75f;
private final float bufferedFractionToLiveEdgeForQualityIncrease = 0.75f;
public Factory(BandwidthMeter bandwidthMeter) {
this.bandwidthMeter = bandwidthMeter;
}
#Override
public ClassAdaptiveTrackSelection createTrackSelection(TrackGroup group, int... tracks) {
Log.d(ClassAdaptiveTrackSelection.class.getSimpleName(), " Video player quality reset to Auto");
sHLSQuality = HLSQuality.Auto;
return new ClassAdaptiveTrackSelection(
group,
tracks,
bandwidthMeter,
maxInitialBitrate,
minDurationForQualityIncreaseMs,
maxDurationForQualityDecreaseMs,
minDurationToRetainAfterDiscardMs,
bandwidthFraction,
bufferedFractionToLiveEdgeForQualityIncrease
);
}
}
private static HLSQuality sHLSQuality = HLSQuality.Auto;
private final BandwidthMeter bandwidthMeter;
private final int maxInitialBitrate;
private final long minDurationForQualityIncreaseUs;
private final long maxDurationForQualityDecreaseUs;
private final long minDurationToRetainAfterDiscardUs;
private final float bandwidthFraction;
private final float bufferedFractionToLiveEdgeForQualityIncrease;
private int selectedIndex;
private int reason;
private ClassAdaptiveTrackSelection(TrackGroup group,
int[] tracks,
BandwidthMeter bandwidthMeter,
int maxInitialBitrate,
long minDurationForQualityIncreaseMs,
long maxDurationForQualityDecreaseMs,
long minDurationToRetainAfterDiscardMs,
float bandwidthFraction,
float bufferedFractionToLiveEdgeForQualityIncrease) {
super(group, tracks);
this.bandwidthMeter = bandwidthMeter;
this.maxInitialBitrate = maxInitialBitrate;
this.minDurationForQualityIncreaseUs = minDurationForQualityIncreaseMs * 1000L;
this.maxDurationForQualityDecreaseUs = maxDurationForQualityDecreaseMs * 1000L;
this.minDurationToRetainAfterDiscardUs = minDurationToRetainAfterDiscardMs * 1000L;
this.bandwidthFraction = bandwidthFraction;
this.bufferedFractionToLiveEdgeForQualityIncrease = bufferedFractionToLiveEdgeForQualityIncrease;
selectedIndex = determineIdealSelectedIndex(Long.MIN_VALUE);
reason = C.SELECTION_REASON_INITIAL;
}
#Override
public void updateSelectedTrack(long playbackPositionUs, long bufferedDurationUs, long availableDurationUs) {
long nowMs = SystemClock.elapsedRealtime();
// Stash the current selection, then make a new one.
int currentSelectedIndex = selectedIndex;
selectedIndex = determineIdealSelectedIndex(nowMs);
if (selectedIndex == currentSelectedIndex) {
return;
}
if (!isBlacklisted(currentSelectedIndex, nowMs)) {
// Revert back to the current selection if conditions are not suitable for switching.
Format currentFormat = getFormat(currentSelectedIndex);
Format selectedFormat = getFormat(selectedIndex);
if (selectedFormat.bitrate > currentFormat.bitrate
&& bufferedDurationUs < minDurationForQualityIncreaseUs(availableDurationUs)) {
// The selected track is a higher quality, but we have insufficient buffer to safely switch
// up. Defer switching up for now.
selectedIndex = currentSelectedIndex;
} else if (selectedFormat.bitrate < currentFormat.bitrate
&& bufferedDurationUs >= maxDurationForQualityDecreaseUs) {
// The selected track is a lower quality, but we have sufficient buffer to defer switching
// down for now.
selectedIndex = currentSelectedIndex;
}
}
// If we adapted, update the trigger.
if (selectedIndex != currentSelectedIndex) {
reason = C.SELECTION_REASON_ADAPTIVE;
}
}
#Override
public int getSelectedIndex() {
return selectedIndex;
}
#Override
public int getSelectionReason() {
return reason;
}
#Override
public Object getSelectionData() {
return null;
}
#Override
public int evaluateQueueSize(long playbackPositionUs, List<? extends MediaChunk> queue) {
if (queue.isEmpty()) {
return 0;
}
int queueSize = queue.size();
long bufferedDurationUs = queue.get(queueSize - 1).endTimeUs - playbackPositionUs;
if (bufferedDurationUs < minDurationToRetainAfterDiscardUs) {
return queueSize;
}
int idealSelectedIndex = determineIdealSelectedIndex(SystemClock.elapsedRealtime());
Format idealFormat = getFormat(idealSelectedIndex);
// If the chunks contain video, discard from the first SD chunk beyond
// minDurationToRetainAfterDiscardUs whose resolution and bitrate are both lower than the ideal
// track.
for (int i = 0; i < queueSize; i++) {
MediaChunk chunk = queue.get(i);
Format format = chunk.trackFormat;
long durationBeforeThisChunkUs = chunk.startTimeUs - playbackPositionUs;
if (durationBeforeThisChunkUs >= minDurationToRetainAfterDiscardUs
&& format.bitrate < idealFormat.bitrate
&& format.height != Format.NO_VALUE && format.height < 720
&& format.width != Format.NO_VALUE && format.width < 1280
&& format.height < idealFormat.height) {
return i;
}
}
return queueSize;
}
private int determineIdealSelectedIndex(long nowMs) {
if (sHLSQuality != HLSQuality.Auto) {
Log.d(ClassAdaptiveTrackSelection.class.getSimpleName(), " Video player quality seeking for " + String.valueOf(sHLSQuality));
for (int i = 0; i < length; i++) {
Format format = getFormat(i);
if (HLSUtil.getQuality(format) == sHLSQuality) {
Log.d(ClassAdaptiveTrackSelection.class.getSimpleName(), " Video player quality set to " + String.valueOf(sHLSQuality));
return i;
}
}
}
Log.d(ClassAdaptiveTrackSelection.class.getSimpleName(), " Video player quality seeking for auto quality " + String.valueOf(sHLSQuality));
long bitrateEstimate = bandwidthMeter.getBitrateEstimate();
long effectiveBitrate = bitrateEstimate == BandwidthMeter.NO_ESTIMATE
? maxInitialBitrate : (long) (bitrateEstimate * bandwidthFraction);
int lowestBitrateNonBlacklistedIndex = 0;
for (int i = 0; i < length; i++) {
if (nowMs == Long.MIN_VALUE || !isBlacklisted(i, nowMs)) {
Format format = getFormat(i);
if (format.bitrate <= effectiveBitrate && HLSUtil.isQualityPlayable(format)) {
Log.d(ClassAdaptiveTrackSelection.class.getSimpleName(), " Video player quality auto quality found " + String.valueOf(sHLSQuality));
return i;
} else {
lowestBitrateNonBlacklistedIndex = i;
}
}
}
return lowestBitrateNonBlacklistedIndex;
}
private long minDurationForQualityIncreaseUs(long availableDurationUs) {
boolean isAvailableDurationTooShort = availableDurationUs != C.TIME_UNSET
&& availableDurationUs <= minDurationForQualityIncreaseUs;
return isAvailableDurationTooShort
? (long) (availableDurationUs * bufferedFractionToLiveEdgeForQualityIncrease)
: minDurationForQualityIncreaseUs;
}
static void setHLSQuality(HLSQuality HLSQuality) {
sHLSQuality = HLSQuality;
}
}
Hope it helps someone.
You can check out ExoPlayer_TrackSelection from github for changing video quality manually.
I have developed a music player for Android and the app works perfectly. When I try to open a song from file manager it opens the music player but not playing the song.
I tried to fetch the uri using getintent().getdata() but don't know how convert the uri to my required format.
Help me to solve the issue.
Class to play songs
public static void playAll(final Context context, final long[] list, int position,
final long sourceId, final IdType sourceType,
final boolean forceShuffle) {
if (list == null || list.length == 0 || mService == null) {
return;
}
try {
if (forceShuffle) {
mService.setShuffleMode(MusicService.SHUFFLE_NORMAL);
}
final long currentId = mService.getAudioId();
final int currentQueuePosition = getQueuePosition();
if (position != -1 && currentQueuePosition == position && currentId == list[position]) {
final long[] playlist = getQueue();
if (Arrays.equals(list, playlist)) {
mService.play();
return;
}
}
if (position < 0) {
position = 0;
}
mService.open(list, forceShuffle ? -1 : position, sourceId, sourceType.mId);
mService.play();
} catch (final RemoteException ignored) {
} catch (IllegalStateException e) {
e.printStackTrace();
}
}
I am trying to do a jigsaw puzzle app in android. In this, I have split a Bitmap into many small chunks. These chunks are then displayed in a GridViewNow I need to shuffle them. Then, I need to know each image chunk's actualPosition(where the piece was supposed to be, its actual location in the image) and its currentPosition(where the piece is currently located). actualPosition and currentPosition are 2 integer arrays. So is there a way that I can get each image chunk's currentPosition and actualPosition after the shuffling so that after every move that the user make I can check wether every image chunk's actualPosition equals its currentPosition. If so the user wins the game. Can anyone please help me out.
Below is the number puzzle game in pure Java that works. Can be run from command line.
It re-prints the whole matrix after every move (not pretty). It demos the basic game.
I hope most of the code is self explanatory. This shows the basic 2-dim mapping of the game, position tracking, validating based on numbers. Have fun.
package madhav.turangi.basic.game;
import java.util.Random;
import java.util.Scanner;
public class NumberPuzzle {
int size;
int[][] arr;
int spaceRow;
int spaceCol;
int turnsTook;
public NumberPuzzle(int size) {
this.size = size;
arr = new int[size][size];
}
void init()
{
for(int r=0; r<size; r++)
{
for(int c=0; c<arr[r].length; c++)
{
arr[r][c] = r*size + c + 1; // row-column of cell to its value equation
}
}
spaceRow = spaceCol = size - 1; // bottom-right cell index
}
int readUserInput()
{
int value = -1;
boolean valid = false;
do {
System.out.printf("To move space [0 - Up, 1 - Down, 2 - Left, 3 - Right] : ? ");
Scanner sc = new Scanner(System.in);
String line = sc.nextLine();
try
{
value = Integer.parseInt(line);
valid = (value>=0 && value<=3);
}
catch(NumberFormatException ne)
{
}
if(! valid) System.out.println("== Invalid ==");
} while (! valid);
return value;
}
void swap(int aRow, int aCol, int withRow, int withCol)
{
int temp = arr[aRow][aCol];
arr[aRow][aCol] = arr[withRow][withCol];
arr[withRow][withCol] = temp;
}
boolean moveUp()
{
if(spaceRow != 0)
{
int newSpaceRow = spaceRow - 1;
swap(spaceRow, spaceCol, newSpaceRow, spaceCol);
spaceRow--;
return true;
}
else
{
return false;
}
}
boolean moveDown()
{
if(spaceRow != size-1)
{
int newSpaceRow = spaceRow + 1;
swap(spaceRow, spaceCol, newSpaceRow, spaceCol);
spaceRow++;
return true;
}
else
{
return false;
}
}
boolean moveRight()
{
if(spaceCol != size-1)
{
int newSpaceCol = spaceCol + 1;
swap(spaceRow, spaceCol, spaceRow, newSpaceCol);
spaceCol++;
return true;
}
else
{
return false;
}
}
boolean moveLeft()
{
if(spaceCol != 0)
{
int newSpaceCol = spaceCol - 1;
swap(spaceRow, spaceCol, spaceRow, newSpaceCol);
spaceCol--;
return true;
}
else
{
return false;
}
}
void shuffle()
{
Random rnd = new Random(System.currentTimeMillis());
boolean moved = false;
int attemptCount = 1;
int maxMoves = 20;
for(int moveCount=0; moveCount<maxMoves; moveCount++, attemptCount++)
{
int randomMoveDir = rnd.nextInt(4);
moved = move(randomMoveDir);
if(! moved) moveCount--; //ensure maxMoves number of moves
}
System.out.printf("Shuffle attempts %d\n",attemptCount);
}
boolean move(int dir)
{
boolean moved = false;
switch(dir)
{
case 0 : // up
moved = moveUp();
break;
case 1 : // down
moved = moveDown();
break;
case 2 : // left
moved = moveLeft();
break;
case 3 : // right
moved = moveRight();
break;
}
return moved;
}
void prnArray()
{
System.out.println("-- -- -- -- --");
for(int[] row : arr)
{
for(int cellValue : row)
{
String v = (cellValue == 16 ? "" : String.valueOf(cellValue));
System.out.printf("%4s", v);
}
System.out.println();
}
System.out.println("-- -- -- -- --");
}
boolean validate()
{
for(int r=0; r<size; r++)
{
for(int c=0; c<arr[r].length; c++)
{
if(arr[r][c] != (r*size + c + 1))
{
return false;
}
}
}
return true;
}
boolean oneTurn()
{
int dir = readUserInput();
boolean moved = move(dir);
boolean won = false;
if(moved)
{
turnsTook++;
prnArray();
won = validate();
}
else
{
System.out.println("= Invalid =");
}
return won;
}
void play()
{
init();
System.out.println("Before shuffle");
prnArray();
shuffle();
prnArray();
boolean won = false;
while(! won)
{
won = oneTurn();
}
System.out.printf("Won in %d\n", turnsTook);
}
public static void main(String[] args)
{
NumberPuzzle puzzle = new NumberPuzzle(4);
puzzle.play();
}
}
I'm in the process of adding Actionbarsherlock to my app to update the UI for Android 2.2/2.3 users. ABS is working great but I found an issue with older devices where the ListView would hang after the app was opened after a reboot. The app lists all apps with Internet Permission and then adds a few special apps (the app is a firewall) and would hang while trying to display the information.
Originally the code cached the apps after building the list using standard arrays. I want to move the app away from the caching since i think that's a huge reason for some of the hanging. So I've been moving everything from arrays to ArrayLists for easier usage. I ran into one IndexOutofBounds but corrected that one but this one is stumping me completely. Here is my code for getting the apps and sorting code.
Any help would be greatly appreciated and if any other code is needed please ask!
Thanks in advance!
App list code:
int count = 0;
try {
final PackageManager pkgmanager = ctx.getPackageManager();
final List<ApplicationInfo> installed = pkgmanager
.getInstalledApplications(PackageManager.GET_META_DATA);
final HashMap<Integer, DroidApp> map = new HashMap<Integer, DroidApp>();
final Editor edit = prefs.edit();
boolean changed = false;
String name = null;
String cachekey = null;
final String cacheLabel = "cache.label.";
DroidApp app = null;
for (final ApplicationInfo apinfo : installed) {
count = count + 1;
if(applist != null){
applist.doProgress(count);
}
boolean firstseen = false;
app = map.get(apinfo.uid);
// filter applications which are not allowed to access the
// Internet
if (app == null
&& PackageManager.PERMISSION_GRANTED != pkgmanager
.checkPermission(Manifest.permission.INTERNET,
apinfo.packageName)) {
continue;
}
// try to get the application label from our cache -
// getApplicationLabel() is horribly slow!!!!
cachekey = cacheLabel + apinfo.packageName;
name = prefs.getString(cachekey, "");
if (name.length() == 0) {
// get label and put on cache
name = pkgmanager.getApplicationLabel(apinfo).toString();
edit.putString(cachekey, name);
changed = true;
firstseen = true;
}
if (app == null) {
app = new DroidApp();
app.uid = apinfo.uid;
app.names = new ArrayList<String>();
app.names.add(name);
app.appinfo = apinfo;
map.put(apinfo.uid, app);
} else {
app.names.add(name);
}
app.firstseen = firstseen;
// check if this application is selected
if (!app.selected_wifi
&& Arrays.binarySearch(selected_wifi, app.uid) >= 0) {
app.selected_wifi = true;
}
if (!app.selected_3g
&& Arrays.binarySearch(selected_3g, app.uid) >= 0) {
app.selected_3g = true;
}
if (!app.selected_roaming
&& Arrays.binarySearch(selected_roaming, app.uid) >= 0) {
app.selected_roaming = true;
}
if (!app.selected_vpn
&& Arrays.binarySearch(selected_vpn, app.uid) >= 0) {
app.selected_vpn = true;
}
}
if (changed) {
edit.commit();
}
/* add special applications to the list */
List<DroidApp> special = new ArrayList<DroidApp>();
special.add(new DroidApp(
SPECIAL_UID_ANY,
"(Any application) - Same as selecting all applications", false, false, false, false));
special.add(new DroidApp(SPECIAL_UID_KERNEL, "(Kernel) - Linux kernel", false, false, false, false));
special.add(new DroidApp(android.os.Process.getUidForName("root"), "(root) - Applications running as root", false, false, false, false));
special.add(new DroidApp(android.os.Process.getUidForName("media"),"Media server", false, false, false, false));
special.add(new DroidApp(android.os.Process.getUidForName("vpn"), "VPN networking", false, false, false, false));
special.add(new DroidApp(android.os.Process.getUidForName("shell"), "Linux shell", false, false, false, false));
special.add(new DroidApp(android.os.Process.getUidForName("gps"), "GPS", false, false, false, false));
for (int i = 0; i < special.size(); i++) {
app = special.get(i);
if (app.uid != -1 && !map.containsKey(app.uid)) {
// check if this application is allowed
if (Arrays.binarySearch(selected_wifi, app.uid) >= 0) {
app.selected_wifi = true;
}
if (Arrays.binarySearch(selected_3g, app.uid) >= 0) {
app.selected_3g = true;
}
if (Arrays.binarySearch(selected_roaming, app.uid) >= 0) {
app.selected_roaming = true;
}
if (Arrays.binarySearch(selected_vpn, app.uid) >= 0) {
app.selected_vpn = true;
}
map.put(app.uid, app);
}
}
/* convert the map into an array */
applications = new ArrayList<DroidApp>(map.values());
return applications;
Sorting code:
class ApplicationSort implements Comparator<DroidApp> {
#Override
public int compare(DroidApp o1, DroidApp o2) {
if (o1.firstseen != o2.firstseen) {
return (o1.firstseen ? -1 : 1);
}
boolean o1_selected;
boolean o2_selected;
boolean vpnenabled = getApplicationContext()
.getSharedPreferences(Api.PREFS_NAME, 0).getBoolean(
Api.PREF_VPNENABLED, false);
boolean roamenabled = getApplicationContext()
.getSharedPreferences(Api.PREFS_NAME, 0).getBoolean(
Api.PREF_ROAMENABLED, false);
if (vpnenabled && !roamenabled) {
o1_selected = o1.selected_3g || o1.selected_wifi
|| o1.selected_vpn;
o2_selected = o2.selected_3g || o2.selected_wifi
|| o2.selected_vpn;
if (o1_selected == o2_selected) {
return String.CASE_INSENSITIVE_ORDER.compare(
o1.names.get(0).toString(), o2.names.get(0).toString());
}
if (o1_selected)
return -1;
}
if (roamenabled && !vpnenabled) {
o1_selected = o1.selected_3g || o1.selected_wifi
|| o1.selected_roaming;
o2_selected = o2.selected_3g || o2.selected_wifi
|| o2.selected_roaming;
if (o1_selected == o2_selected) {
return String.CASE_INSENSITIVE_ORDER.compare(
o1.names.get(0).toString(), o2.names.get(0).toString());
}
if (o1_selected)
return -1;
}
if (roamenabled && vpnenabled) {
o1_selected = o1.selected_3g || o1.selected_wifi
|| o1.selected_roaming || o1.selected_vpn;
o2_selected = o2.selected_3g || o2.selected_wifi
|| o2.selected_roaming || o2.selected_vpn;
if (o1_selected == o2_selected) {
return String.CASE_INSENSITIVE_ORDER.compare(
o1.names.get(0).toString(), o2.names.get(0).toString());
}
if (o1_selected)
return -1;
}
if (!roamenabled && !vpnenabled) {
o1_selected = o1.selected_3g || o1.selected_wifi;
o2_selected = o2.selected_3g || o2.selected_wifi;
if (o1_selected == o2_selected) {
return String.CASE_INSENSITIVE_ORDER.compare(
o1.names.get(0).toString(), o2.names.get(0).toString());
}
if (o1_selected)
return -1;
}
return 1;
}
}
ListView code that calls the sorting class
private void createListView(final String searching) {
this.dirty = false;
boolean results = false;
List<DroidApp> namesearch = new ArrayList<DroidApp>();
final List<DroidApp> appnames = Api.getApps(this, null);
if (searching != null && searching.length() > 1) {
for (DroidApp app : appnames) {
for (String str : app.names) {
if (str.contains(searching.toLowerCase())
|| str.toLowerCase().contains(
searching.toLowerCase())) {
namesearch.add(app);
results = true;
}
}
}
}
final List<DroidApp> apps = results ? namesearch
: searching.equals("") ? appnames
: new ArrayList<Api.DroidApp>();
// Sort applications - selected first, then alphabetically
Collections.sort(apps, new ApplicationSort());
I do not see what is DroidApp, but you are using something like this:
o1.names.get(0) and o2.names.get(0)
Is it possible that some of the DroidApps have empty names lists?
I made a statement and if it is true it continues, I want to stop this "continue" and make another statement for example touchdown and touchup.
here is my code
private void updateRunning(float deltaTime) {
List<TouchEvent> touchEvents = game.getInput().getTouchEvents();
int len = touchEvents.size();
for (int i = 0; i < len; i++) {
TouchEvent event = touchEvents.get(i);
if (event.type != TouchEvent.TOUCH_UP)
continue;
world.doodle.DOODLE_Y = 3;
touchPoint.set(event.x, event.y);
guiCam.touchToWorld(touchPoint);
if (OverlapTester.pointInRectangle(pauseBounds, touchPoint)) {
Assets.clicks();
state = GAME_PAUSED;
return;
}
}
world.update(deltaTime, game.getInput().getAccelX());
if (world.score != lastScore) {
lastScore = world.score;
scoreString = "" + lastScore;
}
if (world.state == World.WORLD_STATE_NEXT_LEVEL) {
state = GAME_LEVEL_END;
}
if (world.state == World.WORLD_STATE_GAME_OVER) {
state = GAME_OVER;
if (lastScore >= Settings.highscores[4])
scoreString = "new highscore: " + lastScore;
else
scoreString = "score: " + lastScore;
Settings.addScore(lastScore);
Settings.save(game.getFileIO());
}
}
Little confused by what you are asking, but perhaps an else if?
if (event.type == TouchEvent.TOUCH_UP) {
/* do something for TOUCH_UP event */
} else if (event.type == TouchEvent.TOUCH_DOWN) {
/* do something for TOUCH_DOWN event */
} else {
/* do something else */
}
You can't stop a continue after you execute it.
Try adding break; where you want it to stop.