Java Code Examples for roboguice.util.Ln#e()

The following examples show how to use roboguice.util.Ln#e() . You can vote up the ones you like or vote down the ones you don't like, and go to the original project or source file by following the links above each example. You may check out the related API usage on the sidebar.
Example 1
Source File: Security.java    From oversec with GNU General Public License v3.0 6 votes vote down vote up
/**
 * Verifies that the data was signed with the given signature, and returns
 * the verified purchase. The data is in JSON format and signed
 * with a private key. The data also contains the {@link PurchaseState}
 * and product ID of the purchase.
 *
 * @param base64PublicKey the base64-encoded public key to use for verifying.
 * @param signedData      the signed JSON string (signed, not encrypted)
 * @param signature       the signature for the data, signed with the private key
 */
public static boolean verifyPurchase(String base64PublicKey, String signedData, String signature) {
    if (signedData == null) {
        Ln.e(TAG, "data is null");
        return false;
    }

    boolean verified = false;
    if (!TextUtils.isEmpty(signature)) {
        PublicKey key = Security.generatePublicKey(base64PublicKey);
        verified = Security.verify(key, signedData, signature);
        if (!verified) {
            Ln.w(TAG, "signature does not match data.");
            return false;
        }
    }
    return true;
}
 
Example 2
Source File: HistoryManager.java    From AndFChat with GNU General Public License v3.0 6 votes vote down vote up
public void loadHistory() {
    if (sessionData.getSessionSettings().useHistory()) {
        Ln.d("Load history from disk!");
        String filename = sessionData.getCharacterName() + ".hist";

            FileInputStream fis;
            try {
                Ln.d("loading file: " + filename);
                fis = context.openFileInput(filename);
                ObjectInputStream is = new ObjectInputStream(fis);

                histories = (HashMap<Channel, List<ChatEntry>>) is.readObject();
                Ln.d("loading successfully! channels: " + histories.size());
                is.close();

                return;
            } catch (Exception e) {
                e.printStackTrace();
                Ln.e("loading failed!");

            }

        histories = new HashMap<Channel, List<ChatEntry>>();
    }
}
 
Example 3
Source File: ChatroomManager.java    From AndFChat with GNU General Public License v3.0 6 votes vote down vote up
public void addChat(Chatroom chatroom, ChatEntry entry) {
    if (chatroom == null) {
        Ln.e("Cant find chatroom, is null");
        return;
    } else if (entry == null) {
        Ln.e("Cant find entry, is null");
        return;
    }

    chatroom.addChat(entry);
    eventManager.fire(entry, chatroom);

    entry.setOwned(sessionData.isUser(entry.getOwner()));

    if (!chatroom.hasNewMessage() && !isActiveChat(chatroom)) {
        chatroom.setHasNewMessage(true);
        eventManager.fire(chatroom, ChatroomEventType.NEW_MESSAGE);
    }
}
 
Example 4
Source File: ChatroomManager.java    From AndFChat with GNU General Public License v3.0 6 votes vote down vote up
public void addMessage(Chatroom chatroom, ChatEntry entry) {
    if (chatroom == null) {
        Ln.e("Cant find chatroom, is null");
        return;
    } else if (entry == null) {
        Ln.e("Cant find entry, is null");
        return;
    }

    chatroom.addMessage(entry);
    eventManager.fire(entry, chatroom);

    entry.setOwned(sessionData.isUser(entry.getOwner()));

    if (!chatroom.hasNewMessage() && !isActiveChat(chatroom)) {
        chatroom.setHasNewMessage(true);
        eventManager.fire(chatroom, ChatroomEventType.NEW_MESSAGE);
    }
}
 
Example 5
Source File: VariableHandler.java    From AndFChat with GNU General Public License v3.0 6 votes vote down vote up
@Override
public void incomingMessage(ServerToken token, String msg, List<FeedbackListener> feedbackListener) throws JSONException {
    if (token == ServerToken.VAR) {
        JSONObject data = new JSONObject(msg);
        String variableName = data.getString("variable");

        Variable variable;
        try {
            variable = Variable.valueOf(variableName);
        }
        catch(IllegalArgumentException e) {
            Ln.e("Can't parse variable enum for '"+variableName+"' - skipping!");
            return;
        }

        if (variable.getType() == Integer.class) {
            sessionData.setVariable(variable, data.getInt("value"));
        }
    }
}
 
Example 6
Source File: NominatimGeocoder.java    From callerid-for-android with GNU General Public License v3.0 6 votes vote down vote up
public List<Address> getFromLocationName(String locationName, int maxResults)
		throws IOException {
	final Map<String,String> urlVariables = new HashMap<String, String>();
	urlVariables.put("location", locationName);
	urlVariables.put("maxResults", Integer.toString(maxResults));
	
	try{
		// Nominatim does not handle the HTTP request header "Accept" according to RFC.
		// If any Accept header other than */* is sent, Nominatim responses with HTTP 406 (Not Acceptable).
		// So instead of the rather simple line:
		// final Place[] places = restTemplate.getForObject("http://nominatim.openstreetmap.org/search?q={location}&format=json&addressdetails=1&limit={maxResults}", Place[].class, urlVariables);
		// we have to manually set the Accept header and make things a bit more complicated.
		
		final HttpHeaders requestHeaders = new HttpHeaders();
		requestHeaders.set("Accept", "*/*");
		final HttpEntity<?> requestEntity = new HttpEntity(requestHeaders);
		final ResponseEntity<Place[]> responseEntity = restTemplate.exchange("http://nominatim.openstreetmap.org/search?q={location}&format=json&addressdetails=1&limit={maxResults}",HttpMethod.GET, requestEntity, Place[].class, urlVariables);
		final Place[] places = responseEntity.getBody();
       	return parseResponse(places);
	}catch(RestClientException e){
		Ln.e(e);
		return new ArrayList<Address>();
	}
}
 
Example 7
Source File: RecentCallsFragment.java    From callerid-for-android with GNU General Public License v3.0 6 votes vote down vote up
@Override
protected void onException(Exception e) throws RuntimeException {
	if (e instanceof CallerIDLookup.NoResultException) {
		if(offlineGeocoderResult == null){
			line1View.setText(lookupNoResult);
		}else{
			// We're already displaying the offline geolocation results... so just leave that there.
		}
	} else {
		Ln.e(e);
		if(offlineGeocoderResult == null){
			line1View.setText(lookupError);
		}else{
			// We're already displaying the offline geolocation results... so just leave that there.
		}
	}
	labelView.setText("");
}
 
Example 8
Source File: SimpleSymmetricEncryptionParamsFragment.java    From oversec with GNU General Public License v3.0 6 votes vote down vote up
@Override
public void saveState(Bundle b) {
    try {
        List<Long> keyIds = mKeysAdapter == null ? Collections.synchronizedList(new ArrayList<Long>()) : mKeysAdapter.getSelectedKeyIds();
        long[] a = new long[keyIds.size()];
        int i = 0;
        synchronized (keyIds) {
            for (Long id : keyIds) {
                a[i] = id;
                i++;
            }
        }

        b.putLongArray(EXTRA_SELECTED_KEY_IDS, a);

        b.putInt(EXTRA_PADDER_POS, mSpPaddingSym.getSelectedItemPosition());
    } catch (Exception ex) {
        Ln.e(ex, "error saving state!");
    }
}
 
Example 9
Source File: SymmetricEncryptionParamsFragment.java    From oversec with GNU General Public License v3.0 6 votes vote down vote up
@Override
public void saveState(Bundle b) {
    try {
        List<Long> keyIds = mKeysAdapter.getSelectedKeyIds();
        long[] a = new long[keyIds.size()];
        int i = 0;
        for (Long id : keyIds) {
            a[i] = id;
            i++;
        }

        b.putLongArray(EXTRA_SELECTED_KEY_IDS, a);

        b.putInt(EXTRA_PADDER_POS, mSpPaddingSym.getSelectedItemPosition());
    } catch (Exception ex) {
        Ln.e(ex, "error saving state!");
    }
}
 
Example 10
Source File: GpgEncryptionParamsFragment.java    From oversec with GNU General Public License v3.0 5 votes vote down vote up
@Override
public void saveState(Bundle b) {
    try {
        b.putLongArray(EXTRA_PUBLIC_KEYS,
                mEditorPgpEncryptionParams.getAllPublicKeyIds());

        b.putBoolean(EXTRA_SIGN, mCbSign.isChecked());

        b.putInt(EXTRA_PADDER_POS, mSpPaddingPgp.getSelectedItemPosition());
    } catch (Exception ex) {
        Ln.e(ex, "error saving state!");
    }
}
 
Example 11
Source File: MainActivity.java    From oversec with GNU General Public License v3.0 5 votes vote down vote up
public static void closeOnPanic() {
    if (mInstance != null) {
        try {
            mInstance.finish();
        } catch (Exception ex) {
            Ln.e(ex);
        }
    }
}
 
Example 12
Source File: ChatroomManager.java    From AndFChat with GNU General Public License v3.0 5 votes vote down vote up
public void addTyping(Chatroom chatroom, String typingStatus) {
    if (chatroom == null) {
        Ln.e("Cant find chatroom, is null");
        return;
    } else if (typingStatus == null) {
        Ln.e("Typing Status is null");
        return;
    }

    chatroom.setTypingStatus(typingStatus);
    eventManager.fire(chatroom, ChatroomEventType.NEW_TYPING_STATUS);
}
 
Example 13
Source File: LookupAsyncTask.java    From callerid-for-android with GNU General Public License v3.0 5 votes vote down vote up
@Override
protected void onException(Exception e) throws RuntimeException {
	// since we're about to start a new lookup,
	// we want to cancel any lookups in progress
	if (geocoderAsyncTask != null)
		geocoderAsyncTask.cancel(true);

	if(isCancelled()) return; //don't do any UI things if the task was cancelled
	
	if (e instanceof CallerIDLookup.NoResultException) {
		if(offlineGeocoderResult == null){
			text.setText(lookupNoResult);
		}else{
			// We're already displaying the offline geolocation results... so just leave that there.
			if(showMap){
				geocoderAsyncTask = new GeocoderAsyncTask(getContext(),offlineGeocoderResult,layout);
				geocoderAsyncTask.execute();
			}
		}
	} else {
		Ln.e(e);
		if(offlineGeocoderResult == null){
			text.setText(lookupError);
		}else{
			// We're already displaying the offline geolocation results... so just leave that there.
			if(showMap){
				geocoderAsyncTask = new GeocoderAsyncTask(getContext(),offlineGeocoderResult,layout);
				geocoderAsyncTask.execute();
			}
		}
	}
	address.setVisibility(View.GONE);
	if(layout.findViewById(R.id.map_view)!=null) layout.findViewById(R.id.map_view).setVisibility(View.GONE);
	image.setImageDrawable(null);
}
 
Example 14
Source File: FlistWebSocketHandler.java    From AndFChat with GNU General Public License v3.0 5 votes vote down vote up
@Override
public void onTextMessage(String payload) {
    if (!disconnected) {
        if (sessionData.getSessionSettings().useDebugChannel()) {
            FCharacter systemChar = characterManager.findCharacter(CharacterManager.USER_SYSTEM_INPUT);
            ChatEntry entry = new MessageEntry(systemChar, payload);
            Chatroom chatroom = chatroomManager.getChatroom(AndFChatApplication.DEBUG_CHANNEL_NAME);
            chatroomManager.addMessage(chatroom, entry);
        }

        ServerToken token;
        try {
            token = ServerToken.valueOf(payload.substring(0, 3));
            Ln.v("Incoming message with token: " + token.name());
        } catch (IllegalArgumentException e) {
            Ln.w("Can't find token '" + payload.substring(0, 3) + "' in ServerToken-Enum! -> Ignoring Message");
            return;
        }

        if (handlerMap.containsKey(token)) {
            try {
                // If the message has message, give them to handler without token.
                // FeedbackListener will only be called once and removed.
                if (payload.length() > 3) {
                    handlerMap.get(token).incomingMessage(token, payload.substring(4), feedbackListenerMap.remove(token));
                } else {
                    handlerMap.get(token).incomingMessage(token, "", feedbackListenerMap.remove(token));
                }
            } catch (JSONException ex) {
                Ln.e("Can't parse json: " + payload);
            }
        } else {
            Ln.e("Can't find handler for token '" + token + "' -> Ignoring Message");
        }
    }
}
 
Example 15
Source File: FlistWebSocketConnection.java    From AndFChat with GNU General Public License v3.0 5 votes vote down vote up
public void connect() {
     try {
         WebSocketOptions options = new WebSocketOptions();

         options.setMaxFramePayloadSize(256000);
application.getConnection().connect(sessionData.getHost(), handler, options);
         eventManager.fire(ConnectionEventListener.ConnectionEventType.CONNECTED);
     } catch (WebSocketException e) {
         e.printStackTrace();
         Ln.e("Exception while connecting");
     }
 }
 
Example 16
Source File: CallerIDApplication.java    From callerid-for-android with GNU General Public License v3.0 5 votes vote down vote up
private void installHttpHandler(long httpCacheSize, File httpCacheDir ){
    try{
        HttpResponseCache result = new HttpResponseCache(httpCacheDir, httpCacheSize);
        ResponseCache.setDefault(result);
        URL.setURLStreamHandlerFactory(new OkHttpURLStreamHandlerFactory(new OkHttpClient()));
    }catch(Exception e){
    	Ln.e(e, "Failed to set up okhttp");
    }
}
 
Example 17
Source File: PingHandler.java    From AndFChat with GNU General Public License v3.0 5 votes vote down vote up
@Override
public void connected() {
    running = true;
    lastPIN = System.currentTimeMillis();

    Runnable timeoutChecker = new Runnable() {
        @Override
        public void run() {
            try {
                int losts = 0;
                while(running) {

                    if (sessionData.isInChat()) {
                        Ln.v("Check PIN messages");
                        if (System.currentTimeMillis() - lastPIN > MAX_TIME_BETWEEN_PINGS) {
                            losts++;
                        } else {
                            losts = 0;
                        }

                        if (losts == 1 || losts == 2) {
                            connection.sendMessage(ClientToken.PIN);
                        }
                        else if (losts == 3) {
                            Ln.d("3 Lost PIN - Disconnecting");
                            connection.closeConnection(context);
                            running = false;
                            losts = 0;
                        }
                    }
                    Thread.sleep(MAX_TIME_BETWEEN_PINGS);
                }
            } catch (InterruptedException e) {
                Ln.e(e);
            }
        }
    };

    new Thread(timeoutChecker).start();
}
 
Example 18
Source File: Core.java    From oversec with GNU General Public License v3.0 4 votes vote down vote up
private Core(Context ctx) {
    mCtx = ctx;

    mMainThread = Looper.getMainLooper().getThread();

    mUiThreadVars = new UiThreadVars(this);

    mHandlerThread = new HandlerThread(
            "UI");
    mHandlerThread.setPriority(Thread.MAX_PRIORITY);
    mHandlerThread.start();
    mUiHandler = new Handler(mHandlerThread.getLooper(), this);

    mMainHandler = new Handler(Looper.getMainLooper(), mMainHandlerCallback);

    mDb = new Db(this);
    mCryptoHandlerFacade = CryptoHandlerFacade.Companion.getInstance(mCtx);
    mEncryptionCache = new EncryptionCache(mCtx, mCryptoHandlerFacade);
    // mIgnoreCache = IgnoreUIRQCache.getInstance(mCtx);
    mOverlays = new Overlays(this, ctx);
    mNm =
            (NotificationManager) ctx.getSystemService(Context.NOTIFICATION_SERVICE);
    mCbm = (ClipboardManager) mCtx.getSystemService(Context.CLIPBOARD_SERVICE);


    setOversecAccessibilityService(mOversecAccessibilityService); //force notification update


    BroadcastReceiver aIntentReceiver = new BroadcastReceiver() {
        @Override
        public void onReceive(Context context, Intent intent) {
            try {
                String action = intent.getAction();
                Ln.d("OOPS %s", action);
                if (Intent.ACTION_SCREEN_OFF.equals(action)) {
                    mScreenOn = false;
                    onScreenOff_UI();
                } else {
                    if (Intent.ACTION_SCREEN_ON.equals(action)) {
                        mScreenOn = true;
                        onScreenOn_UI();

                    }
                }
            } catch (Throwable ex) {
                Ln.e(ex, "WTF ?");
            }
        }
    };
    IntentFilter filter = new IntentFilter();
    filter.addAction(Intent.ACTION_SCREEN_OFF);
    filter.addAction(Intent.ACTION_SCREEN_ON);
    mCtx.registerReceiver(aIntentReceiver, filter, null, mUiHandler);

    CoreContract.Companion.init(this);
}
 
Example 19
Source File: HistoryManager.java    From AndFChat with GNU General Public License v3.0 4 votes vote down vote up
public void saveHistory() {
    if (sessionData.getSessionSettings().useHistory() && sessionData.getCharacterName() != null) {
        Ln.d("Save history to disk!");
        String filename = sessionData.getCharacterName() + ".hist";

        if (context.deleteFile(filename)) {
            Ln.d("Old file named: " + filename + " deleted");
        }

        try {
            FileOutputStream fos = context.openFileOutput(filename, Context.MODE_PRIVATE);
            ObjectOutputStream outputStream = new ObjectOutputStream(fos);

            // Filter history, do not save notations
            HashMap<Channel, List<ChatEntry>> filteredHistories = new HashMap<Channel, List<ChatEntry>>();
            for (Channel channel : histories.keySet()) {
                // Care about the channel filter
                if (sessionData.getSessionSettings().logChannel() || channel.getType() != ChatroomType.PUBLIC_CHANNEL) {
                    List<ChatEntry> channelMessages = new ArrayList<ChatEntry>(histories.get(channel));

                    // Clean up chat history by removing everything than messages and emotes.
                    ListIterator<ChatEntry> iterator = channelMessages.listIterator();
                    while (iterator.hasNext()) {
                        ChatEntry entry = iterator.next();
                        if (entry.getMessageType() != MessageType.MESSAGE && entry.getMessageType() != MessageType.EMOTE) {
                            iterator.remove();
                        }
                    }

                    filteredHistories.put(channel, channelMessages);
                }
            }

            // Write serialized output
            outputStream.writeObject(filteredHistories);
            outputStream.flush();
            outputStream.close();
            Ln.d("Saving complete:" + histories.size());
        } catch (Exception e) {
            e.printStackTrace();
            Ln.e("Saving failed!");
        }
    }
}
 
Example 20
Source File: GeocoderAsyncTask.java    From callerid-for-android with GNU General Public License v3.0 4 votes vote down vote up
@Override
protected void onException(final Exception e) throws RuntimeException {
	Ln.e(e);
	if(layout.findViewById(R.id.map_view)!=null) layout.findViewById(R.id.map_view).setVisibility(View.GONE);
}